I would like to disable the 'X' (close window in upper right corner) on a main window of an application. Can I do this ? All I have is the window handle passed in from another application. Thanks in advance.
Printable View
I would like to disable the 'X' (close window in upper right corner) on a main window of an application. Can I do this ? All I have is the window handle passed in from another application. Thanks in advance.
Set the ControlBox property to False, but that's going to disable your Minimize and Maximize as well.
The code assumes one Form and a command button named Command1. The code below will suppress clicking on the X on the top right corner as well as <Alt><F4> key presses. The only way to unload the form is clicking Command1 button or from the Task Manger I reckon.
Code:
Option Explicit
Dim bUnload As Boolean
Private Sub Command1_Click()
bUnload = True
Unload Me
End Sub
Private Sub Form_Load()
bUnload = False
End Sub
Private Sub Form_Unload(Cancel As Integer)
If bUnload Then
Else
Cancel = 1
End If
End Sub