Prithiv
Prithiv

Reputation: 514

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?

Upvotes: 10

Views: 4954

Answers (1)

Reza Aghaei
Reza Aghaei

Reputation: 125277

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.

Upvotes: 17

Related Questions