Force Windows Form to stay Open even if attempted to be Closed?
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
Re: Force Windows Form to stay Open even if attempted to be Closed?
If you don't want to close the form, then in your Closing event write
Code:
//This will force the form to stay open
e.Cancel=True
Re: Force Windows Form to stay Open even if attempted to be Closed?
Thanks A LOT. I have done it once but forgot:). I new it was so easy but could not remember.
Thanks!!!
Re: Force Windows Form to stay Open even if attempted to be Closed?
Quote:
Originally Posted by stardv
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. :)
Re: Force Windows Form to stay Open even if attempted to be Closed?
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
Re: Force Windows Form to stay Open even if attempted to be Closed?
jmcilhinney, your helper class sounds interesting, but the link you gave states:
Quote:
Edit:
Attachment removed. See post #1.
So, is the class at some other url? Is there a C# version?
Re: Force Windows Form to stay Open even if attempted to be Closed?
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