Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disabling Close window option in windows 7

My application is in VB.net with 3.5 framework. I want to disable the close button ("[X]") on the main form of the application while doing some processing.

I have achieved the disabling by overriding the "ReadOnly Property CreateParams()" of the form. This is working fine, as both the control button on the form and close option on right click in the taskbar shows them as disabled.

This fulfills my needs on Windows XP but not on Windows 7. In Windows 7, right clicking on the application icon in the TaskBar shows a different menu...which has a new "Close window" option.

Close in the original menu still shows it as disabled (this old menu is hidden, but can be shown by holding Shift key and right click on the application icon in TaskBar). Now I need to disable this "Close window" option as well...and only for my application.

Is there a method for doing this programmatically?

like image 707
user706023 Avatar asked Mar 07 '26 05:03

user706023


1 Answers

Use:

Private Sub MyForm_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
    e.Cancel = True
End Sub

Edit:

Yes, you should check the e.CloseReason property. The sender's type is another parameter you can key off of to decide whether to cancel the close request or not.

like image 111
Brian Mulcahy Avatar answered Mar 08 '26 20:03

Brian Mulcahy