简体   繁体   中英

Make a richtextbox open from file in a set location

I need to have a richtextbox (rtbUsers) load up a .txt or .rtf (Whatever is easiest) on either form loadup or when a button is pressed (btnLoad) from: C:\\ProgramData\\Project\\test.txt

The only code I have found is for the openfile dialogue, but I need it from a set location. So I am asking if anyone could please give me the code that I need. Thanks :)

Just call the LoadFile method:

richTextBox1.LoadFile("mypathandfile.rtf")

For a text file, there is an overload you can use:

richTextBox1.LoadFile("mypathandfile.txt", RichTextBoxStreamType.PlainText)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM