在Windows 7中禁用“关闭窗口"选项 [英] Disabling Close window option in windows 7

查看:104
本文介绍了在Windows 7中禁用“关闭窗口"选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在VB.net中使用3.5框架开发的应用程序.在执行某些处理时,我已禁用了应用程序主窗体上的关闭(X)按钮.我已经通过覆盖表格的ReadOnly属性CreateParams()"实现了禁用.由于窗体上的控制按钮和任务栏中的右键单击关闭选项均显示为禁用,因此此方法工作正常.这可以满足我在Windows XP OS上而不是Windows 7 OS上的需求.与在Windows 7中一样,右键单击任务栏上的应用程序图标将显示另一个菜单,该菜单具有新的关闭窗口"选项.

原始菜单中的关闭仍显示为已禁用(此旧菜单已隐藏,但可以通过按住Shift键并右键单击任务栏上的应用程序图标来显示).现在,我还需要仅针对我的应用程序禁用此关闭窗口"选项.

有没有一种方法可以通过编程方式做到这一点.另外,请让我知道其他解决方案.

问候,

Hassan

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

推荐答案

您可以覆盖句柄事件System.Windows.Window.ClosingSystem.Windows.Window.OnClosing.在处理程序中,使用类型为System.ComponentModel.CancelEventArgs的事件参数arguments并将其属性Cancel分配给true.这将防止关闭此窗口.做任何您想在此事件上进行的其他事情(隐藏它,等等)

那就是WPF的秘诀.对于System.Windows.Forms —完全相同,System.Windows.Forms具有相同名称的事件和虚函数.

—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


要禁用跳转"菜单,必须更改该菜单的内容.我不确定如何在.Net中执行此操作,但是使用互操作服务当然可以实现. Google是您的朋友.

顺便说一句,您可以通过更改主窗体标题栏的属性来消除大多数close-app功能.另外,别忘了禁用也用于关闭应用程序的Alt-F4热键.
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.


这篇关于在Windows 7中禁用“关闭窗口"选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆