close application

G

Guest

Hi
It seems like the winforms has the minimise, maximise and control box properties...but not 'close' application that can disable the closing of the applicatrion by clicking on the X on the right hand side of the screen.

The only way to be this is to set the controlbox property to false, but this takes away the ability to mininmise and maximise

Any help would be appriciared.
 
G

Guest

To cancel the closure of a form, set the Cancel property of the CancelEventArgs passed to your forms event handler(for the Closing event) to true

I believe it is possible to hide the close button by calling a few Win32 API functions, but the same cannot be done solely from the .NET framwork. And I dont think its really wise to hide the button. ITs is better to apply some logic to prevent the application from closing in the Closing event as mentioned earlier

All the best
 
G

Guest

Thanks a lot. You are right...it is better to close the application using logic..

Thanks for your help..

Regards....
 
H

Herfried K. Wagner [MVP]

* "=?Utf-8?B?c3Bhcm1hcg==?= said:
It seems like the winforms has the minimise, maximise and control box
properties...but not 'close' application that can disable the closing of
the applicatrion by clicking on the X on the right hand side of the
screen.

\\\
Private Declare Auto Function GetSystemMenu Lib "user32.dll" ( _
ByVal hWnd As IntPtr, _
ByVal bRevert As Int32 _
) As IntPtr

Private Declare Auto Function GetMenuItemCount Lib "user32.dll" ( _
ByVal hMenu As IntPtr _
) As Int32

Private Declare Auto Function DrawMenuBar Lib "user32.dll" ( _
ByVal hWnd As IntPtr _
) As Int32

Private Declare Auto Function RemoveMenu Lib "user32.dll" ( _
ByVal hMenu As IntPtr, _
ByVal nPosition As Int32, _
ByVal wFlags As Int32 _
) As Int32

Private Const MF_BYPOSITION As Int32 = &H400
Private Const MF_REMOVE As Int32 = &H1000

Private Sub RemoveCloseButton(ByVal frmForm As Form)
Dim hMenu As IntPtr, n As Int32
hMenu = GetSystemMenu(frmForm.Handle, 0)
If Not hMenu.Equals(IntPtr.Zero) Then
n = GetMenuItemCount(hMenu)
If n > 0 Then
RemoveMenu(hMenu, n - 1, MF_BYPOSITION Or MF_REMOVE)
RemoveMenu(hMenu, n - 2, MF_BYPOSITION Or MF_REMOVE)
DrawMenuBar(frmForm.Handle)
End If
End If
End Sub
///
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top