Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ResizeEnd event is not triggered when resizing the form by maximize button?

In my application the ResizeEnd event is triggered when resizing the form by dragging the corners, but it will not be triggered when I click the maximize button.

The Resize event does not work in my scenario so I need to use ResizeEnd event.

Why is this event not triggered while resizing the form by maximize button? Or can anyone suggest alternatives?

like image 612
Prithiv Avatar asked Sep 23 '16 05:09

Prithiv


1 Answers

The ResizeEnd event is raised when the user finishes resizing a form, typically by dragging one of the borders or the sizing grip located on the lower-right corner of the form, and then releasing it. It also is raised when the user moves a form.

If for any reason you need maximizing the window cause raising the ResizeEnd event you can raise the event this way:

const int WM_SYSCOMMAND = 0x0112;
const int SC_MAXIMIZE = 0xF030;
protected override void WndProc(ref Message m)
{
    base.WndProc(ref m);
    if (m.Msg == WM_SYSCOMMAND) 
    {
        if (m.WParam == (IntPtr)SC_MAXIMIZE) 
        {
            //the window has been maximized
            this.OnResizeEnd(EventArgs.Empty);
        }
    }
}

Note

  • The Resize event is raised also when the form is maximized.
  • The Layout event is a suitable event if you want to handle a custom layout.
like image 143
Reza Aghaei Avatar answered Oct 05 '22 11:10

Reza Aghaei