469,299 Members | 2,106 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,299 developers. It's quick & easy.

C# Windows form's Close Control Box

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
Dec 20 '05 #1
3 6582
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

Dec 20 '05 #2
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

Dec 20 '05 #3
Thanks Roland!
The FormClose works fine.

"Roland" <ro******************@gmx.net>
???????:11**********************@g44g2000cwa.googl egroups.com...
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

Dec 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Evan Kontos | last post: by
1 post views Thread by Codemonkey | last post: by
6 posts views Thread by Ayende Rahien | last post: by
3 posts views Thread by Brian Keating EI9FXB | last post: by
3 posts views Thread by Dan | last post: by
1 post views Thread by Scott Davies | last post: by
reply views Thread by Scott Davies | last post: by
4 posts views Thread by Rod Gill | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.