Blog coding and discussion of coding about JavaScript, PHP, CGI, general web building etc.

Friday, April 1, 2016

Event when a Window gets maximized/

Event when a Window gets maximized/"un-maximized"?


Is there an Event that is fired when you maximize a WinForm Form or un-maximize it again?

Before you say Resize or SizeChanged: Those get only fired if the Size actually changes. If your window happens to be equal in size to the maximized window, they do not fire. Location looks like the next best bet, but that again feels like gambling on a coincidence.

Answer by Matt for Event when a Window gets maximized/"un-maximized"?


If there's no obvious event to listen for, you're probably going to need to hook into the Windows API and catch the appropriate message (Google turns up that you'll want to intercept the WM_SYSCOMMAND message: http://www.codeguru.com/forum/archive/index.php/t-234554.html).

Answer by Reed Copsey for Event when a Window gets maximized/"un-maximized"?


You can do this by overriding WndProc:

protected override void WndProc( ref Message m )  {      if( m.Msg == 0x0112 ) // WM_SYSCOMMAND      {          // Check your window state here          if (m.WParam == new IntPtr( 0xF030 ) ) // Maximize event - SC_MAXIMIZE from Winuser.h          {                // THe window is being maximized          }      }      base.WndProc(ref m);  }  

This should handle the event on any window. SC_RESTORE is 0xF120, and SC_MINIMIZE is 0XF020, if you need those constants, too.

Answer by Lorenzo Melato for Event when a Window gets maximized/"un-maximized"?


Another little addition in order to check for the restore to the original dimension and position after the maximization:

protected override void WndProc(ref Message m)  {      base.WndProc(ref m);        // WM_SYSCOMMAND      if (m.Msg == 0x0112)      {          if (m.WParam == new IntPtr(0xF030) // Maximize event - SC_MAXIMIZE from Winuser.h              || m.WParam == new IntPtr(0xF120)) // Restore event - SC_RESTORE from Winuser.h          {              UpdateYourUI();          }      }  }  

Hope this help.

Answer by 816-8055 for Event when a Window gets maximized/"un-maximized"?


class="descans">

I had the same problem, and I could solve it without overriding. Because I have a PictureBox in dock mode "Fill" I could use it's SizeChanged event, witch fired also on maximizing the window.

Answer by Geotarget for Event when a Window gets maximized/"un-maximized"?


Suprising that no one mentioned the inbuilt .NET method.

This way you don't need to override the Window Message Processing handler.

It even captures maximize/restore events caused by double-clicking the window titlebar, which the WndProc method does not.

Copy this in and link it to the "Resize" event handler on the form.

    FormWindowState LastWindowState = FormWindowState.Minimized;      private void Form1_Resize(object sender, EventArgs e) {            // When window state changes          if (WindowState != LastWindowState) {              LastWindowState = WindowState;                  if (WindowState == FormWindowState.Maximized) {                    // Maximized!              }              if (WindowState == FormWindowState.Normal) {                    // Restored!              }          }        }  

Answer by Hobis for Event when a Window gets maximized/"un-maximized"?


' Great tip. So if it helps to VisualBasic In Code  Private Const WM_SYSCOMMAND As Integer = &H112  Private Const SC_MAXIMIZE As Integer = &HF030  ' # WndProcess ????  Protected Overrides Sub WndProc(ByRef m As Message)      If m.Msg.Equals(WM_SYSCOMMAND) Then          If (m.WParam.ToInt32.Equals(SC_MAXIMIZE)) Then              Me.p_FullScreen()              Return          End If      End If        MyBase.WndProc(m)  End Sub  

Answer by Eske Rahn for Event when a Window gets maximized/"un-maximized"?


I'm a newbie here so comments not allowed, but this IS a comment to the clean answer by GeoTarget:

The first line OUGHT to be slightly changed to nullable, to catch if the form is started Minimized:

FormWindowState? LastWindowState = null;  

And a banal suggestion: Move the assignment of LastWindowState to after the "if"s, so the user can easily check not only what you go to, but also what it came from:

FormWindowState? LastWindowState = null;  private void Form1_Resize(object sender, EventArgs e) {      // When window state changes      if (WindowState != LastWindowState) {          if (WindowState == FormWindowState.Maximized) {              // Maximized!          }          if (WindowState == FormWindowState.Normal) {              // Restored!          }          LastWindowState = WindowState;      }  }  


Fatal error: Call to a member function getElementsByTagName() on a non-object in D:\XAMPP INSTALLASTION\xampp\htdocs\endunpratama9i\www-stackoverflow-info-proses.php on line 72

Related Posts:

0 comments:

Post a Comment

Popular Posts

Fun Page

Powered by Blogger.