-
The other day we all learned how to disable the close button
with GetSystemMenu and RemoveMenu. They will allow you to
disable (grey-out) the shutdown X in the control box. But
this will still leave ALT+F4 as a means to shut down your app.
Is there any way to intercept this keypress sequence to force
the user into using a command button to quit the app? Or a
way to disable ALT+F4 from closing your app?
-
There's a couple of things you can do. The first is to set the ControlBox property of the form to False but this will also remove the system menu completly.
The second thing to do is to add code to the QueryUnload event.
Code:
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
If UnloadMode = vbFormControlMenu Then
'the user is trying to close the window by
'either keying ALT+F4 or by using the "X" button
Cancel = True
End If
End Sub
Have a look in MSDN library for other values you can check for in the QueryUnload event.
Good luck!
-
Thanks,
The second method is the one I was looking for. And
the MSDN library for this event has other useful tidbits that may come in handy.
-
altF4 disable
Thank you Joacim Andersson. Your answer worked immediately and solved a big problem for us!:)