Prevent form from closing

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]
 
K

KWienhold

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
 
I

Ignacio Machin \( .NET/ C# MVP \)

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();
 

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