Click here to Skip to main content
15,902,869 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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.
Sergey Alexandrovich Kryukov 22-Jan-13 23:15pm    
What do you try to achieve?

1 solution

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:[^].

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.

[EDIT #1]

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.

[EDIT #2]

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.

Share this answer
Kuthuparakkal 22-Jan-13 23:45pm    
Sergey Alexandrovich Kryukov 22-Jan-13 23:49pm    
Thank you very much,

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