-
Notifications
You must be signed in to change notification settings - Fork 1
OpenFileDialog
ITAgnesmeyer edited this page Feb 22, 2019
·
1 revision
With the object OpenFileDialog a file dialog can be opened.
private void FileOpen_Click(object sender, MouseClickEventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
//Title of the Dialog
ofd.Title = "Open a Text File...";
//All Values have to be separated with \0
ofd.Filter = "All File(*.*)\0*.*\0Text(*.txt)\0*.txt\0";
//Shows Text(*.txt) as default
ofd.DefaultFilterIndex = 2;
//Show the Dialog modal to the current Form.
if (ofd.Show(this))
{
//Read the selected Path
string fileName = ofd.File;
//File Actions.
string text = File.ReadAllText(fileName);
this._TextBox.Text = text;
this.Text = "Little Edit:" + fileName;
}
}