Prevent form from closing

  • Thread starter Thread starter sravan_reddy001
  • Start date Start date
S

sravan_reddy001

i want to prevent a form from closing..

to do this i want to handle the formClosing or FormClosed events.
from here i want to prevent the form from closing.

New instance of same form should not be used.

is there any way to do this?

is it posiible to do the same thing with anycode?

[i posted the same thing in VB. sorry if u find that too... reply in
one post is enough]
 
i want to prevent a form from closing..

to do this i want to handle the formClosing or FormClosed events.
from here i want to prevent the form from closing.

New instance of same form should not be used.

is there any way to do this?

is it posiible to do the same thing with anycode?

[i posted the same thing in VB. sorry if u find that too... reply in
one post is enough]

Setting e.Cancel to true in the FormClosing-event should do the trick.

hth,
Kevin Wienhold
 
Hi,

Setting e.Cancel to true in the FormClosing-event should do the trick.

You need something else, you need a flag to know when the form is closing
from the code or is the user trying to close it.

bool canClose = false;

void form_Closing(.... )
{
e.Cancel = !canClose;
}

so if you want to close the form you do:

canClose =true;
Close();
 
Back
Top