C# Windows form's Close Control Box

  • Thread starter Thread starter Jason Huang
  • Start date Start date
J

Jason Huang

Hi,

How do I let the X Close Control Box incurr a Close Button when I click the
X Close Control Box?
Thanks for help.


Jason
 
Hi Jason

I hope I understud your question correctly.

You need to implement the FormClosing, resp. FormClosed event.

Here an example:

private void DoMyClosingStuff()
{
// do anything you need to dispose here
}

private void CloseButton_Click(object sender, EventArgs e)
{
DoMyClosingStuff();
this.Close();
}

private void Form1_FormClosing(object sender,
FormClosingEventArgs e)
{
DoMyClosingStuff();
}

Hope this helps
Roland
 
Sorry Jason
I did a little mistake.

You don't need to call again the method 'DoMyClosingStuff()' in the
button click event.
By the line 'this.close' the FormClosing event will be called.

It's enough to write:

private void CloseButton_Click(object sender, EventArgs e)
{
this.Close();
}

Sorry for that missleading
Roland
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top