Close Event

M

MDB

Hello All,

For some reason when my form is closed the closed event is not being fired
off. The form is created using a start up class:

System.Windows.Forms.Application.Run(new frmMain());

Then in the InitializeComponent (which is called from withing the frmMain
class) it has this:

this.Closed +=new EventHandler(frmMain_Closed);

Then I also have this:
 
M

MDB

Must of hit enter sending the post before I was done:

Hello All,

For some reason when my form is closed the closed event is not being fired
off. The form is created using a start up class:

System.Windows.Forms.Application.Run(new frmMain());

Then in the InitializeComponent (which is called from withing the frmMain
class) it has this:

this.Closed +=new EventHandler(frmMain_Closed);

Then I also have this:

private void frmMain_Closed(object sender, EventArgs e)
{
//My code

}

for some reason, the Closed Event will not fire off and I can not figure out
why. Any suggestions?
 
G

Ginny Caughey [MVP]

Probably you have MinimizeBox set to true, which is the default. When you
click on the X, the form won't close but will instead minimize. Change
MinimizeBox to false (or provide a button or menu option that calls
this.Close()) and you will see the event fire.
 
M

MDB

Yep, that was it. Thanks for your reply!


Ginny Caughey said:
Probably you have MinimizeBox set to true, which is the default. When you
click on the X, the form won't close but will instead minimize. Change
MinimizeBox to false (or provide a button or menu option that calls
this.Close()) and you will see the event fire.
 
E

Ercan Turkarslan [MS]

Hi,

You should also keep in mind that, if you call Application.Exit your form
close event will not triggered.

If you should call Application.Exit, you should call Form.Close for all
your open forms prior to that.

Thanks

Ercan Turkarslan
Microsoft Mobile Devices Developer Support
This posting is provided "AS IS" with no warranties, and confers no rights.
 

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

Top