Home All Groups Group Topic Archive Search About

What is the event to trap when user clicks X to close form?

Author
21 Oct 2006 3:59 PM
Robert Dufour
On my form if the user clicks the upper right hand corner to close the form
I want to trap that event and do a check to see if closing is allowed, if
not, I want to stop the form closing action.

Can anyone tell me how I can do this?

Thanks for any help
Bob

Author
21 Oct 2006 8:06 PM
Tiago Salgado
Form_Close event is fired when u try to close form.

On Sat, 21 Oct 2006 16:59:07 +0100, Robert Dufour <bduf***@sgiims.com> 
wrote:

Show quoteHide quote
> On my form if the user clicks the upper right hand corner to close the 
> form
> I want to trap that event and do a check to see if closing is allowed, if
> not, I want to stop the form closing action.
>
> Can anyone tell me how I can do this?
>
> Thanks for any help
> Bob
>
>



Author
21 Oct 2006 9:28 PM
Ryan S. Thiele
Don't forget the Form.Closing Event. Which is fired before the disposal.

--
Thiele Enterprises - The Power Is In Your Hands Now!

--
"Tiago Salgado" <tiagosalgado.develo***@gmail.com> wrote in message
news:op.thsfgaqtdysvon@tiagosalgado...
Form_Close event is fired when u try to close form.

On Sat, 21 Oct 2006 16:59:07 +0100, Robert Dufour <bduf***@sgiims.com>
wrote:

> On my form if the user clicks the upper right hand corner to close the
> form
> I want to trap that event and do a check to see if closing is allowed, if
> not, I want to stop the form closing action.
>
> Can anyone tell me how I can do this?
>
> Thanks for any help
> Bob
>
>



Author
21 Oct 2006 9:48 PM
Herfried K. Wagner [MVP]
"Robert Dufour" <bduf***@sgiims.com> schrieb:
> On my form if the user clicks the upper right hand corner to close the
> form I want to trap that event and do a check to see if closing is
> allowed, if not, I want to stop the form closing action.

In addition to the other replies:

If you are using .NET 2.0, check out the form's 'FormClosing' event too.

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://dotnet.mvps.org/dotnet/faqs/>
Author
22 Oct 2006 1:44 AM
rowe_newsgroups
There is also the option to override the WndProc method if you really
needed to.

Thanks,

Seth Rowe


Herfried K. Wagner [MVP] wrote:
Show quoteHide quote
> "Robert Dufour" <bduf***@sgiims.com> schrieb:
> > On my form if the user clicks the upper right hand corner to close the
> > form I want to trap that event and do a check to see if closing is
> > allowed, if not, I want to stop the form closing action.
>
> In addition to the other replies:
>
> If you are using .NET 2.0, check out the form's 'FormClosing' event too.
>
> --
>  M S   Herfried K. Wagner
> M V P  <URL:http://dotnet.mvps.org/>
>  V B   <URL:http://dotnet.mvps.org/dotnet/faqs/>
Author
22 Oct 2006 9:47 AM
gene kelley
On Sat, 21 Oct 2006 11:59:07 -0400, "Robert Dufour" <bduf***@sgiims.com> wrote:

>On my form if the user clicks the upper right hand corner to close the form
>I want to trap that event and do a check to see if closing is allowed, if
>not, I want to stop the form closing action.
>
>Can anyone tell me how I can do this?
>
>Thanks for any help
>Bob
>

In VB6, there was the QueryUnload event which had an UnloadMode argument, one of
which was vbFormControlMenu which was specific to the "X" button and the control
menu, "Close". 

In .Net, AFAIK, there is no functional equivalent short of using the WndProc method.
FormClosing event will fire when the "X" button is pressed (3-User Closing), but it
also fires for the same reason if Me.Close() is called  - 3-User Closing.

Gene
Author
22 Oct 2006 12:25 PM
rdufour
Thank you all

Show quoteHide quote
"gene kelley" <o***@by.me> wrote in message
news:tcemj2p9n2q86umk17o5qvohg2qkd8mlv2@4ax.com...
> On Sat, 21 Oct 2006 11:59:07 -0400, "Robert Dufour" <bduf***@sgiims.com>
> wrote:
>
>>On my form if the user clicks the upper right hand corner to close the
>>form
>>I want to trap that event and do a check to see if closing is allowed, if
>>not, I want to stop the form closing action.
>>
>>Can anyone tell me how I can do this?
>>
>>Thanks for any help
>>Bob
>>
>
> In VB6, there was the QueryUnload event which had an UnloadMode argument,
> one of
> which was vbFormControlMenu which was specific to the "X" button and the
> control
> menu, "Close".
>
> In .Net, AFAIK, there is no functional equivalent short of using the
> WndProc method.
> FormClosing event will fire when the "X" button is pressed (3-User
> Closing), but it
> also fires for the same reason if Me.Close() is called  - 3-User Closing.
>
> Gene