Event triggered after window maximization

I am looking for an event from a form called after . Maximum or minimized window.

As far as I know, there is such an event as SizeChanged or WndProc that can handle the maximized window, but it is right after the user tries to maximize the window, and it is not called after the window is fully maximized.

I'm looking for an event like ResizeEnd, but maybe it's called MaximizedEnd or MinimizedEnd

Is there any way to do this?

+3
source share
6 answers

This is what Gabriel’s decision will look in detail. I do not think there is an event for WindoStateChanged.

, , . , 3 . , , , m.Msg , , . WM_ http://www.autohotkey.com/docs/misc/SendMessageList.htm.

    protected override void WndProc(ref Message m)
    {
        FormWindowState previousWindowState = this.WindowState;

        base.WndProc(ref m);

        FormWindowState currentWindowState = this.WindowState;

        if (previousWindowState != currentWindowState && currentWindowState == FormWindowState.Maximized)
        {
            // TODO: Do something the window has been maximized

        }
    }

, 3 , . . , , . Yore .

public Form1()
{
    InitializeComponent();

    this.SizeChanged +=new EventHandler(Form1_SizeChanged);
    FormMaximized += new EventHandler(Form1_FormMaximized);

    _CurrentWindowState = this.WindowState;
    if (_CurrentWindowState == FormWindowState.Maximized)
    {
        FireFormMaximized();
    }
}

public event EventHandler FormMaximized;
private void FireFormMaximized()
{
    if (FormMaximized != null)
    {
        FormMaximized(this, EventArgs.Empty);
    }
}

private FormWindowState _CurrentWindowState;
private void Form1_SizeChanged(object sender, EventArgs e)
{
    if (this.WindowState == FormWindowState.Maximized && _CurrentWindowState != FormWindowState.Maximized)
    {
        FireFormMaximized();
    }
    _CurrentWindowState = this.WindowState;
}

void Form1_FormMaximized(object sender, EventArgs e)
{
    //TODO Put you're code here
}
+1

, :

protected override void OnSizeChanged(EventArgs e) {
  if (this.WindowState == FormWindowState.Maximized) {
    MessageBox.Show("Max!");
  }
  base.OnSizeChanged(e);
}

, . :

protected override void OnSizeChanged(EventArgs e) {
  if (this.WindowState == FormWindowState.Maximized) {
    this.BeginInvoke(new MethodInvoker(delegate { MessageBox.Show("Maxed"); }));
  }
  base.OnSizeChanged(e);
}

MessageBox.Show(...) .

+6

, resizeBegin resizeEnd - winform.

private bool resize_flag = true;
    private void Form1_Resize(object sender, EventArgs e)
    {
        if (!resize_flag) return;
        //your code here
        resize_flag = true;
    }

    private void Form1_ResizeBegin(object sender, EventArgs e)
    {
        resize_flag = false;
    }

    private void Form1_ResizeEnd(object sender, EventArgs e)
    {
        //your code here
        resize_flag = true;
    }

, ! resizeEnd , - windowState, . , WndProc() - , winform, ...

+2

, , Windows, , . - , , . , , , , windowstate, SizedChanged, , .

0

, wndProc WM_SYSCOMMAND.

protected override void WndProc(ref Message m)
    {
        if ((UInt32)m.Msg == Constant.WM_SYSCOMMAND)
        {
            switch ((UInt32)m.WParam)
            {
                case Constant.SC_MAXIMIZE:

                case Constant.SC_RESTORE:

                default:
                    break;
            }
        }
        base.WndProc(ref m);
    }
0

, , , , - , .

, , .

:

Public Event Maximized(sender As Object, e As EventArgs)

Create a custom event:

Private Sub frmMain_ResizeEnd(sender As Object, e As EventArgs) Handles Me.ResizeEnd
    If Me.WindowState = FormWindowState.Maximized Then RaiseEvent Maximized(sender, Nothing)
End Sub

Handle your custom event:

Private Sub frmMain_Maximized(sender As Object, e As EventArgs) Handles Me.Maximized

End Sub

or

Private Sub frmMain_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    AddHandler Me.Maximized, AddressOf MaximizedEventMethod
End Sub

Private Sub MaximizedEventMethod(sender As Object, e As EventArgs)
    'add your code here
End Sub
0
source

All Articles