winforms应用程序中的任务栏事件 [英] taskbar event in winforms application

查看:137
本文介绍了winforms应用程序中的任务栏事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果用户点击任务栏,我想知道以窗口形式(winforms)触发哪个事件。我刚刚尝试了Activated和Deactivated事件,但它没有工作。我的意思是这些事件触发了很多次。

I want to know which event is firing in window form(winforms) if the user click on the taskbar. I just tried Activated and Deactivated events and, it''s not working.I mean these events are triggering so many times.

推荐答案

任务栏事件不属于你的申请。它们与Windows shell交互,shell激活或停用您的应用程序。你想要调查这些事件是正确的,但你不能说它不起作用或触发这么多次。它们以完全正确的方式触发。您多次只是调试的结果,这自然会导致停用。要断言真实行为,请使用,例如,记录而不是调试器。



因此,在常规应用程序中,您无法处理这些事件:它们属于过程资源管理器,而不是你的。通过Windows任务管理器删除资源管理器,您将看到它(警告!此实验将需要系统重新启动)。



也许你需要类似的东西(请参阅我对这个问题的评论)。您可以基于 System.Windows.Forms.NotifyIcon 开发应用程序: http://msdn.microsoft.com/en-us/library/system.windows.forms.notifyicon.aspx [ ^ ]。



在这种方法中,UI将基于您在任务栏中的点击次数,但是在其自定义工具栏区域(通常位于任务栏右侧的系统托盘上)。您仍然可以使用表格。







结论:最有可能的是,您仍然需要处理激活事件而不需要其他事情。 NotifyIcon 样式用于应用程序,这是特殊的,当它们很好地关注它们时。查看为标准系统实用程序安装的工具栏。







一个重要的如果您使用 NotifyItem 和表单,请提供建议。在这种情况下,在任务栏中显示您的表单是完全多余的,因此使用属性 System.Windows.Forms.Form.ShowInTaskbar ,将其指定为false。 br $>


-SA
Task bar events are not part of your application at all. They interact with Windows shell, and the shell activate or deactivate your application. You idea about looking into these events was correct, but you cannot say that "it''s not working" or "triggering so many times". They are triggered exactly in exactly right way. You "many times" is simply a consequence of your debugging, which naturally contributes to deactivation. To assert the real behavior, use, for example, logging instead of the debugger.

So, in a "regular" application you cannot handle these events: they belong to the process "Explorer", not yours. Delete Explorer by "Windows Task Manager", and you will see it (warning! this experiment will require system re-boot).

Maybe you need something similar (please see my comment to the question). You can develop your application based on System.Windows.Forms.NotifyIcon: http://msdn.microsoft.com/en-us/library/system.windows.forms.notifyicon.aspx[^].

In this approach, the UI will be based on your clicks in the task bar, but on its custom toolbars area (normally on system tray on the right of task bar). You still can use Forms with that.



Conclusion: most likely, you still need to handle activation events and nothing else. NotifyIcon style is used for applications, which are "special", when it''s good to keep an eye on them. Look at the tool bars installed for standard system utilities.



One important advice if you use NotifyItem and a form. In this case, showing your form(s) in task bar is totally redundant, so use the property System.Windows.Forms.Form.ShowInTaskbar, assign it to false.

—SA


这篇关于winforms应用程序中的任务栏事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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