Hello!
The object called dlgOpenFile is of type OpenFileDialog.
In this example the eventhandler OnFileOpen is called when the Open File in
a menu is clicked.
Here we call the OpenFileDialog and select a filename to be opened and then
if the Open
button is selected we call the OpenFile method.
Now to my question: I just wonder when is the file opened. Is it at the same
time as
the static method File.ReadAllText(filename);
is called
or
is it automatically done in the OpenFileDialog?
private void OnFileOpen(object sender, EventArgs e)
{
if (dlgOpenFile.ShowDialog() == DialogResult.OK)
{
filename = dlgOpenFile.FileName;
OpenFile();
}
}
protected void OpenFile()
{
try
{
textBoxEdit.Clear();
textBoxEdit.Text = File.ReadAllText(filename);
}
catch(IOException ex)
{
MessageBox.Show(ex.Message, "Simple Editor",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
//Tony