Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Disable Close Button ?

25 views
Skip to first unread message

Simon Richardson

unread,
Nov 28, 2002, 1:10:22 PM11/28/02
to
On VB.NET form you can disable the Minimise and Maximise buttons but can
you disable the CLOSE button [X] ?

If so how ?

Thank you
Simon


Elan Zhou(MS)

unread,
Nov 29, 2002, 12:16:53 AM11/29/02
to
Hi,

You can try the following code:

Imports System.Runtime.InteropServices
Public Class Form1
Inherits System.Windows.Forms.Form
. . . . . .
. . . . . .
. . . . . .
<DllImport("user32.dll")> _
Private Shared Function GetSystemMenu(ByVal hWnd As IntPtr, ByVal wMsg
As Boolean) As IntPtr
End Function

<DllImport("user32.dll")> _
Private Shared Function RemoveMenu(ByVal hWnd As IntPtr, ByVal
uPosition As Int32, ByVal uFlags As Int32) As Boolean
End Function

<DllImport("user32.dll")> _
Private Shared Function SendMessage(ByVal hWnd As IntPtr, ByVal wMsg As
Int32, ByVal wParam As Int32, ByVal lParam As Int32) As Int32
End Function

Private Const SC_CLOSE As Int32 = &HF060
Private Const MF_BYCOMMAND As Int32 = 0
Private Const WM_NCACTIVATE As Int32 = &H86

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim hMenu As IntPtr
hMenu = GetSystemMenu(Me.Handle, False)
RemoveMenu(hMenu, SC_CLOSE, MF_BYCOMMAND)
SendMessage(Me.Handle, WM_NCACTIVATE, 0, 0)
SendMessage(Me.Handle, WM_NCACTIVATE, 1, 0)
End Sub
End Class


Regards,
Elan Zhou
This posting is provided "AS IS" with no warranties, and confers no rights.
Got .Net? http://www.gotdotnet.com

0 new messages