How to determine when window shape is minimized?

I know that I can get the current state of WindowState, but I want to know if there will be any event that will fire when the user tries to minimize the form.

+70
c # winforms
Jun 27 '09 at 14:29
source share
4 answers

You can use the Resize event and check the Forms.WindowState property in the event.

private void Form1_Resize ( object sender , EventArgs e ) { if ( WindowState == FormWindowState.Minimized ) { // Do some stuff } } 
+101
Jun 27 '09 at 14:34
source share

To get to before , the form has been minimized, you have to connect to the WndProc procedure:

  private const int WM_SYSCOMMAND = 0x0112; private const int SC_MINIMIZE = 0xF020; [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)] protected override void WndProc(ref Message m) { switch(m.Msg) { case WM_SYSCOMMAND: int command = m.WParam.ToInt32() & 0xfff0; if (command == SC_MINIMIZE) { // Do your action } // If you don't want to do the default action then break break; } base.WndProc(ref m); } 

To respond afterwards , the form was minimized in the case of the Resize event, as other answers indicate (included here for completeness):

 private void Form1_Resize (object sender, EventArgs e) { if (WindowState == FormWindowState.Minimized) { // Do your action } } 
+67
Jun 27 '09 at 14:33
source share

I do not know the specific event, but the Resize event fires when the form is minimized, you can check FormWindowState.Minimized in this case

+16
Jun 27 '09 at 14:33
source share

For people who are looking for a WPF window minimize event:

This is a little different. To call back use WindowState:

 private void Form1_Resize(object sender, EventArgs e) { if (WindowState == FormWindowState.Minimized) { // Do some stuff } } 

The event to use is StateChanged (Resize instead):

 public Main() { InitializeComponent(); this.StateChanged += Form1_Resize; } 
+3
Oct 17 '13 at 9:45
source share



All Articles