Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I have an application developed in VB.net with 3.5 framework. I have disabled close (X) button on the main form of the application while doing some processing. I have achieve disabling by "Overriding ReadOnly Property CreateParams()" of the form. This is working fine as both control button on form and close option on right click in the taskbar shows disabled. This fulfill my needs on the Windows XP OS but not on Windows 7 OS. As in Windows 7 right click on application icon in taskbar shows a different menu, which has a new "Close window" option.

The close in original menu still shows 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 through which I can do this programmatically. Also please let me know about any other solutions.

Regards,

Hassan
Posted
Comments
Sergey Alexandrovich Kryukov 13-Apr-11 8:21am    
Tag it: WPF or WinForms?
--SA

You can override System.Windows.Window.OnClosing of handle event System.Windows.Window.Closing. In the handler use event arguments argument of the type System.ComponentModel.CancelEventArgs and assign its property Cancel to true. It will prevent closing this window. Do whatever else you want on this event (hide it, etc.)

That was the recipe for WPF. For System.Windows.Forms — exact same thing, System.Windows.Forms has the event and virtual function of the same names.

—SA
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 13-Apr-11 11:08am    
OP commented:

Thanks for the quick reply, i am using the closing event for other purposes i.e. to close form with different options available in the form. Can there be a way to disable or hide this new option in the "Jump list" on right clicking?

Hassan
Sergey Alexandrovich Kryukov 13-Apr-11 11:13am    
I've no idea what's the "Jump list". Even is event, you can use for different purposes at the same time. You need to explain your requirements more exactly, what do you need to see and what you expect. Do you want to remove "icon menu" (Alt+backspace) or close icon? How a window and application should close, on what condition? What's the main idea?
--SA
hassan_wahpk1 14-Apr-11 0:49am    
My problem is that on right click an application icon, a new menu is shown in windows 7. You can look at it in the following link. I want to remove/disable "Close window" option in this list. Now i assume that you can visualize my requirement. Any suggestions how to do that?

http://www.about-win7.com/jump-lists.html
Sergey Alexandrovich Kryukov 14-Apr-11 13:02pm    
Remove application icon of the application, that's it. Why would you really need it?

The article you shows using jump list off the taskbar, I did not see how it is activated by application icon (I did not find it in the article and I don't have Windows 7 installed to check it up), but if the application icon is a problem, don't use it.

--SA
To disable the "jump" menu, you have to change the contents of that menu. I'm not sure how to do that in .Net, but it's certainly possible using interop services. Google is your friend.

By the way, you can eliminate most of the close-app functionality by changing the properties of the main form's title bar. Also, don't forget to disable the Alt-F4 hot key that is also used to close the application.
 
Share this answer
 
v2
Comments
hassan_wahpk1 14-Apr-11 0:58am    
Thanks for response, could you please elaborate use for "interop services", as i found "Windows API Code Pack" which i think handling new features underneath work for windows 7. And do u have any experience using this API Code Pack. please suggest.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900