all groups > dotnet windows forms > july 2005 >
You're in the

dotnet windows forms

group:

Prevent user from closing form but allow form to close at logout


Prevent user from closing form but allow form to close at logout jquiet
7/30/2005 7:47:02 PM
dotnet windows forms:
I have added this code in an attempt to prevent the user from closing my
simple 1 form application, but the application now prevents logout and
shutdown. What is the proper way to prevent a user from closing the app but
still have it close gracefully at shutdown/logoff?

Private Sub Form1_Closing(ByVal sender As Object, ByVal e As
System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
e.Cancel = True
End Sub

Thanks
RE: Prevent user from closing form but allow form to close at logout Sergey Pikhulya
7/31/2005 3:23:01 PM
Imports System.ComponentModel

Class DemoForm
Inherits Form

Private Const WM_QUERYENDSESSION = &H11

Private canExit As Boolean
Protected Overrides Sub OnClosing(ByVal e As CancelEventArgs)
e.Cancel = Not canExit
End Sub

Protected Overrides Sub WndProc(ByRef m As Message)
If m.Msg = WM_QUERYENDSESSION Then
canExit = True
End If
MyBase.WndProc(m)
End Sub

End Class

[quoted text, click to view]
AddThis Social Bookmark Button