Very simple question - Autoload textbox when startup C#
The tittl开发者_开发技巧e says it all :) I am creating a program in C# forms. The user can write a text, and save it. What i now want, is to autoload this textfile, witch only can be at one location - At the Directory.GetCurrentDIrectory() + "text.txt"
.
So how should this be done?
I am assuming that you want to do this when the form is available, in which case I would recommend using the Form Load event. Just open the file, read its contents, and set the Text
property to the contents in the form load.
It's quite simple really:
//Autoload
var filePath = Path.Combine(Directory.GetCurrentDirectory(), "text.txt");
if(File.Exists(filePath))
yourTextBox.Text = File.ReadAllText(filePath);
As Ryan points out, you could do it in the FormLoad event.
精彩评论