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

◇◆丶佛笑我妖孽 提交于 2020-01-03 14:17:44

问题


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?


回答1:


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.


来源:https://stackoverflow.com/questions/39653055/resizeend-event-is-not-triggered-when-resizing-the-form-by-maximize-button

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!