get rid of close icon in upper right corner

  • Thread starter Thread starter Nancy
  • Start date Start date
N

Nancy

BlankI don't want a user to be able to close a form by selecting the X close icon in the upper right hand corner of the form. I don't know how to reference it. The form class allows access to the min and max icons but I don't see the close icon. Can't find the class that references the latter.

Thanks,
Nancy
 
To get rid of the close icon you have to set the ControlBox of the Form to false. This will also get rid of the Max and Min buttons though

You could, if you still want Max and Min to work correctly but the Close to not work, add a handler to the Closing event

private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e

e.Cancel = true


HT

RS
 
Nancy,

* "Nancy said:
I don't want a user to be able to close a form by selecting the X close icon in the upper right hand corner of the form. I don't
know how to reference it. The form class allows access to the min and max icons but I don't see the close icon. Can't find the
class that references the latter.

\\\
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

''' <summary>
''' Deaktiviert die Schliessen-Systemschaltfläche des in
''' <paramref name="frmForm"/> übergebenen Formulars.
''' </summary>
''' <param name="frmForm">
''' Formular, dessen Schliessen-Systemschaltfläche deaktiviert
''' werden soll.
''' </param>
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
///
 
BlankThanks for the code and ideas Herfried and RS! Sorry for the delayed response, got pulled off onto other problems.

Regards,
Nancy
I don't want a user to be able to close a form by selecting the X close icon in the upper right hand corner of the form. I don't know how to reference it. The form class allows access to the min and max icons but I don't see the close icon. Can't find the class that references the latter.

Thanks,
Nancy
 
Back
Top