Close on system menu (the "X" in the top right side of window)

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

What function is called in response to a click on "Close" on system menu (the
"X" in the top right side of window)?
 
The following events will be called,
Deactivate
Closing
Closed

private void Form1_Closed(object sender, System.EventArgs e)
{
}

private void Form1_Closing(object sender,
System.ComponentModel.CancelEventArgs e)
{
}

private void Form1_Deactivate(object sender, System.EventArgs e)
{
}
 
I tried this but the events weren't call. If I click on the Close nothing
happens. What am I doing wrong?

// private void Form1_Closed(object sender, System.EventArgs e)
// private void Form1_Closing(object sender,
System.ComponentModel.CancelEventArgs e)
private void Form1_Deactivate(object sender, System.EventArgs e)
{
DialogResult result;
if (chng == true)
{
result = MessageBox.Show("Do you want to save your file?",
"Save?", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Exclamation);
if (result == DialogResult.Cancel)
return;
if (result == DialogResult.Yes)
{
if (Filename == null)
{
saveAsToolStripMenuItem_Click(sender, e);
}
if (Filename != null)
{
Cover(); // get text into richTextBox7
using (StreamWriter sr = new StreamWriter(Filename))
{
sr.Write(richTextBox7.Text);
}
}
}
}
}


Amalorpavanathan Yagulasamy(AMAL)MCP said:
The following events will be called,
Deactivate
Closing
Closed

private void Form1_Closed(object sender, System.EventArgs e)
{
}

private void Form1_Closing(object sender,
System.ComponentModel.CancelEventArgs e)
{
}

private void Form1_Deactivate(object sender, System.EventArgs e)
{
}

--
Regards,
Amal [MCP, MCS]
http://geocities.com/techsharing


Scotty said:
What function is called in response to a click on "Close" on system menu (the
"X" in the top right side of window)?
 
Check to see if the events were actually wired to the functions.

--
Jonathan Allen


Scotty said:
I tried this but the events weren't call. If I click on the Close nothing
happens. What am I doing wrong?

// private void Form1_Closed(object sender, System.EventArgs e)
// private void Form1_Closing(object sender,
System.ComponentModel.CancelEventArgs e)
private void Form1_Deactivate(object sender, System.EventArgs e)
{
DialogResult result;
if (chng == true)
{
result = MessageBox.Show("Do you want to save your file?",
"Save?", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Exclamation);
if (result == DialogResult.Cancel)
return;
if (result == DialogResult.Yes)
{
if (Filename == null)
{
saveAsToolStripMenuItem_Click(sender, e);
}
if (Filename != null)
{
Cover(); // get text into richTextBox7
using (StreamWriter sr = new
StreamWriter(Filename))
{
sr.Write(richTextBox7.Text);
}
}
}
}
}


Amalorpavanathan Yagulasamy(AMAL)MCP said:
The following events will be called,
Deactivate
Closing
Closed

private void Form1_Closed(object sender, System.EventArgs e)
{
}

private void Form1_Closing(object sender,
System.ComponentModel.CancelEventArgs e)
{
}

private void Form1_Deactivate(object sender, System.EventArgs e)
{
}

--
Regards,
Amal [MCP, MCS]
http://geocities.com/techsharing


Scotty said:
What function is called in response to a click on "Close" on system
menu (the
"X" in the top right side of window)?
 
How do I do that? (Newbie question)

Jonathan Allen said:
Check to see if the events were actually wired to the functions.

--
Jonathan Allen


Scotty said:
I tried this but the events weren't call. If I click on the Close nothing
happens. What am I doing wrong?

// private void Form1_Closed(object sender, System.EventArgs e)
// private void Form1_Closing(object sender,
System.ComponentModel.CancelEventArgs e)
private void Form1_Deactivate(object sender, System.EventArgs e)
{
DialogResult result;
if (chng == true)
{
result = MessageBox.Show("Do you want to save your file?",
"Save?", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Exclamation);
if (result == DialogResult.Cancel)
return;
if (result == DialogResult.Yes)
{
if (Filename == null)
{
saveAsToolStripMenuItem_Click(sender, e);
}
if (Filename != null)
{
Cover(); // get text into richTextBox7
using (StreamWriter sr = new
StreamWriter(Filename))
{
sr.Write(richTextBox7.Text);
}
}
}
}
}


Amalorpavanathan Yagulasamy(AMAL)MCP said:
The following events will be called,
Deactivate
Closing
Closed

private void Form1_Closed(object sender, System.EventArgs e)
{
}

private void Form1_Closing(object sender,
System.ComponentModel.CancelEventArgs e)
{
}

private void Form1_Deactivate(object sender, System.EventArgs e)
{
}

--
Regards,
Amal [MCP, MCS]
http://geocities.com/techsharing


:

What function is called in response to a click on "Close" on system
menu (the
"X" in the top right side of window)?
 
Look for code like this for each event. It should be in the initialize
component method.

this.Deactivate += new System.EventHandler(this.Form1_Deactivate);
 
Great! Thanks.

I try it with
"private void Form1_Closed(object sender, System.EventArgs e)"
and it worked!

Scott
 
Back
Top