Is there any event occurred when I click on an icon of an application that is running and is minimized on taskbar? I want to call my method when the icon is clicked. The method is coded into the app's resource. Please view picture to get more information:
-
Minimized or pinned? There's a slight difference. – Lloyd Jan 15 '14 at 13:07
-
Please see http://stackoverflow.com/questions/1384161/net-c-window-minimize-event – Pawan Jan 15 '14 at 13:07
-
1Of course there is an event, you see something happening. The notification goes to *Explorer*, not your program. And Explorer will do the normal thing, it restores your window. Indistinguishable from another way to get a window restored, you get the WM_SYSCOMMAND, SC_RESTORE message. The taskbar button is not otherwise available to you to mess with beyond the *very* limited interface it provides. – Hans Passant Jan 15 '14 at 13:09
-
Thanks for your help, Pawan, LIoyd, Hans Passant. – R700 Jan 16 '14 at 01:55
4 Answers
You can use the from Activated event.
public Form1()
{
InitializeComponent();
this.Activated += Form1_Activated;
}
private void Form1_Activated(object sender, EventArgs e)
{
if (this.WindowState == FormWindowState.Minimized)
{
//TODO: take required action here
}
}
P.S.:I am assuming that you are looking a solution for winform application.

- 1,598
- 10
- 14
-
-
this works well for me I Use this : private void Window_Activated(object sender, EventArgs e) { if (WindowState == WindowState.Minimized) { WindowState = WindowState.Maximized; } } so when click on icon taskbar the window get back maximized. – luka Nov 02 '21 at 13:53
If you're using WPF, you can use the Window.StateChanged Event. Definition of this event:
Occurs when the window's WindowState property changes.
For WindowsForms, there is no StateChanged event. You'll have to use the SizeChanged Event and check the WindowState
yourself. Like this:
private void Form1_Resize(object sender, EventArgs e)
{
switch(this.WindowState)
{
case FormWindowState.Minimized: //Your minimized-event code here;
break;
case FormWindowState.Maximized: //Your maximized-event code here;
break;
default: //state is 'Normal':
}
}

- 14,186
- 6
- 41
- 72
Whenever a window is minimized, maximized, or restored, Window.StateChanged
event is fired. You can trap this event and call your function.

- 2,393
- 4
- 18
- 20
If you want to do it for the same application in which your code is then you handle the Resize
and SizeChanged
event of the Form
control for WinForms application and StateChanged
event of Window control for WPF application. When user clicks on the taskbar icon of an application which is minimized to task bar, it is restored and the Resize
(WinForms), SizeChanged
(WindForms) and StateChanged
(WPF) events are raised which you can handle and check for the WindowState
whether it is maximized or normal.
If you want to do it for any other application then I think you will have to use SetWindowsHookEx
Win32 API function ( as described here) so that you will get a collection of open windows in OS and will have to iterate through all such windows to identify and hook into their Resize
event.

- 1
- 1

- 1,638
- 1
- 14
- 17