DotNetNewsgroup.com  
web access to complete list of Microsoft.NET newsgroups
   home   |   control panel login   |   archive  |  
 
  carried group
academic
adonet
aspnet
aspnet.announcements
aspnet.buildingcontrols
aspnet.caching
aspnet.datagridcontrol
aspnet.mobile
aspnet.security
aspnet.webcontrols
aspnet.webservices
assignment_manager
datatools
dotnet.distributed_apps
dotnet.general
dotnet.myservices
dotnet.nternationalization
dotnet.scripting
dotnet.security
dotnet.vjsharp
dotnet.vsa
dotnet.xml
dotnetfaqs
framework
framework.clr
framework.compactframework
framework.component_services
framework.controls
framework.databinding
framework.drawing
framework.enhancements
framework.interop
framework.odbcnet
framework.performance
framework.remoting
framework.sdk
framework.setup
framework.webservices
framework.windowsforms
framework.wmi
frwk.windowsforms.designtime
lang.csharp
lang.jscript
lang.vb
lang.vb.controls
lang.vb.data
lang.vb.upgrade
lang.vc
lang.vc.libraries
  
 
start date: Wed, 22 Aug 2007 04:23:36 -0700,    posted on: microsoft.public.dotnet.framework.windowsforms        back       

Thread Index
  1    ssg31415926
          2    tlkerns
          3    Jeff Johnson
          4    ssg31415926


Detecting when user clicks Red X button   
Is there anyway to detect when the user has clicked the red X button
to exit an application (as opposed to triggering some other event
which runs code which sends the Close() message to the form?

I know I can use the CloseReason property of FormClosingEventArgs but
that shows UserClosing whether they click the Red X or my Close button
(which sends Close() to the form).

Is there any way to determine that it was the red X button they
clicked?
Date:Wed, 22 Aug 2007 04:23:36 -0700   Author:  

RE: Detecting when user clicks Red X button   
You'll have to create a class that inherits from the Form class and override 
WndProc like this:

    Protected Overrides Sub WndProc(ByRef m As Message)
        If ((m.Msg = WM_SYSCOMMAND) AndAlso _
            (m.WParam.ToInt32 = SC_CLOSE)) Then

            'Here is where you perform some action.
        End If

        MyBase.WndProc(m)
    End Sub 'WndProc

where:

    Public Const WM_SYSCOMMAND As Integer = &H112
    Public Const SC_CLOSE As Integer = &HF060     'The Close menu item.

Tony

"ssg31415926" wrote:


> Is there anyway to detect when the user has clicked the red X button
> to exit an application (as opposed to triggering some other event
> which runs code which sends the Close() message to the form?
> 
> I know I can use the CloseReason property of FormClosingEventArgs but
> that shows UserClosing whether they click the Red X or my Close button
> (which sends Close() to the form).
> 
> Is there any way to determine that it was the red X button they
> clicked?
> 
> 
Date:Wed, 22 Aug 2007 06:02:03 -0700   Author:  

Re: Detecting when user clicks Red X button   
"ssg31415926"  wrote in message 
news:1187781816.819663.40430@e9g2000prf.googlegroups.com...


> Is there any way to determine that it was the red X button they
> clicked?


There's no red X button on ANY of my windows....

For reference, this is called the Close button.
Date:Wed, 22 Aug 2007 17:15:50 -0400   Author:  

Re: Detecting when user clicks Red X button   
On 22 Aug, 14:02, tlkerns  wrote:

> You'll have to create a class that inherits from the Form class and override
> WndProc like this:
>
>     Protected Overrides Sub WndProc(ByRef m As Message)
>         If ((m.Msg = WM_SYSCOMMAND) AndAlso _
>             (m.WParam.ToInt32 = SC_CLOSE)) Then
>
>             'Here is where you perform some action.
>         End If
>
>         MyBase.WndProc(m)
>     End Sub 'WndProc
>
> where:
>
>     Public Const WM_SYSCOMMAND As Integer = &H112
>     Public Const SC_CLOSE As Integer = &HF060     'The Close menu item.
>
> Tony
>
> "ssg31415926" wrote:
> > Is there anyway to detect when the user has clicked the red X button
> > to exit an application (as opposed to triggering some other event
> > which runs code which sends the Close() message to the form?
>
> > I know I can use the CloseReason property of FormClosingEventArgs but
> > that shows UserClosing whether they click the Red X or my Close button
> > (which sends Close() to the form).
>
> > Is there any way to determine that it was the red X button they
> > clicked?


Thanks very much for your help.
Date:Thu, 23 Aug 2007 03:53:11 -0700   Author:  

Google
 
Web dotnetnewsgroup.com


COPYRIGHT ?2005, EUROFRONT WORLDWIDE LTD., ALL RIGHT RESERVE  |   Contact us