Click to See Complete Forum and Search --> : Force Windows Form to stay Open even if attempted to be Closed?


stardv
September 29th, 2005, 01:20 PM
I am trying to cancel Close form option for the user. For example when user clicks on “X” close the form I want the to give user Message that the form can not be closed
and keep it open. I tried to catch Form.Closing event and I inputted message there but I am not sure how to force it stay open.

Can you please help

Thanks

Shuja Ali
September 29th, 2005, 01:26 PM
If you don't want to close the form, then in your Closing event write //This will force the form to stay open
e.Cancel=True

stardv
September 29th, 2005, 03:59 PM
Thanks A LOT. I have done it once but forgot:). I new it was so easy but could not remember.

Thanks!!!

Shuja Ali
September 29th, 2005, 04:08 PM
Thanks A LOT. I have done it once but forgot:). I new it was so easy but could not remember.

Thanks!!!
I am glad it helped. :)

jmcilhinney
September 30th, 2005, 02:35 AM
If you specifically want to prevent the user from closing the form using the Close button on the title bar then I suggest you disable it. I don't know why so many people seem to want to distinguish between that and other methods of closing a form, by I've written a helper class that you can use to disable the Close button and also to make a form immovable. It edits the system menu to achieve this, but that is all hidden. You simply create an instance of the class in your form with the appropriate constructor and you're done.

SystemMenuManager class (http://www.vbforums.com/showthread.php?t=351533)

zips
September 30th, 2005, 11:50 AM
jmcilhinney, your helper class sounds interesting, but the link you gave states:Edit:
Attachment removed. See post #1.
So, is the class at some other url? Is there a C# version?

jmcilhinney
September 30th, 2005, 05:11 PM
Sorry, my mistake. Here's a link to the entire thread. The class file is attached, as per that other link, to post #1.

SystemMenuManager class (http://www.vbforums.com/showthread.php?t=351533)