Update: new question here.
I'm writing a very basic text editor (think Notepad with a few more features). When a user hits Ctrl+N or File->New, a blank document is created in a new window, much the way you'd open a new browser window.
The problem is, if the user clicks the close button in the upper right with more than one window open, all form windows are closed, not just the current one.
The way the new form functionality is done is:
The way the exit functionality is handled is:
this.Close() closes all forms, which leads me to believe that maybe the way I'm creating a new document is probably not The Right Way. If this is the case, what is the right way?
I'm writing a very basic text editor (think Notepad with a few more features). When a user hits Ctrl+N or File->New, a blank document is created in a new window, much the way you'd open a new browser window.
The problem is, if the user clicks the close button in the upper right with more than one window open, all form windows are closed, not just the current one.
The way the new form functionality is done is:
Code:
private void newToolStripMenuItem_Click(object sender, EventArgs e)
{
frmMain NewDocument = new frmMain();
NewDocument.Show();
}
The way the exit functionality is handled is:
Code:
protected override void OnFormClosing(FormClosingEventArgs e)
{
if (!isNewDocument && !isSaved()) // Pre-existing document, not saved
{
var result = MessageBox.Show("Do you want to save your changes?", PROGRAM_NAME, MessageBoxButtons.YesNoCancel);
if (result == DialogResult.Yes)
SaveFile();
else if (result == DialogResult.No)
{
initialText = txtText.Text;
this.Close();
}
else if (result == DialogResult.Cancel)
e.Cancel = true;
}
else if (isNewDocument && !isSaved()) // New document, not saved == Save As
{
var result = MessageBox.Show("Do you want to save your changes?", PROGRAM_NAME, MessageBoxButtons.YesNoCancel);
if (result == DialogResult.Yes)
SaveFileAs();
else if (result == DialogResult.No)
{
initialText = txtText.Text;
this.Close();
}
else if (result == DialogResult.Cancel)
e.Cancel = true;
}
}
this.Close() closes all forms, which leads me to believe that maybe the way I'm creating a new document is probably not The Right Way. If this is the case, what is the right way?