Example #1
0
        protected override void WndProc(ref Message m)
        {
            FormWindowState?newWindowState = null;

            if (m.Msg == WinUserConstants.WmSysCommand)
            {
                int wParam = m.WParam.ToInt32() & 0xFFF0;

                if (wParam == WinUserConstants.ScMinimize || wParam == WinUserConstants.ScMaximize || wParam == WinUserConstants.ScRestore)
                {
                    newWindowState = TranslateWindowState(wParam);
                }
            }

            if (newWindowState != null)
            {
                EventHandler <WindowStateChangingEventArgs>?eventHandler = WindowStateChanging;

                if (eventHandler != null)
                {
                    var args = new WindowStateChangingEventArgs(newWindowState.Value);
                    eventHandler(this, args);

                    if (args.Cancel)
                    {
                        return;
                    }
                }
            }

            base.WndProc(ref m);

            if (newWindowState != null)
            {
                WindowStateChanged?.Invoke(this, EventArgs.Empty);
            }
        }
        protected override void WndProc(ref Message m)
        {
            FormWindowState? newWindowState = null;

            if (m.Msg == WinUserConstants.WmSysCommand)
            {
                int wParam = m.WParam.ToInt32() & 0xFFF0;
                if (wParam == WinUserConstants.ScMinimize || wParam == WinUserConstants.ScMaximize ||
                    wParam == WinUserConstants.ScRestore)
                {
                    newWindowState = TranslateWindowState(wParam);
                }
            }

            if (newWindowState != null)
            {
                EventHandler<WindowStateChangingEventArgs> eventHandler = WindowStateChanging;
                if (eventHandler != null)
                {
                    var args = new WindowStateChangingEventArgs(newWindowState.Value);
                    eventHandler(this, args);

                    if (args.Cancel)
                    {
                        return;
                    }
                }
            }

            base.WndProc(ref m);

            if (newWindowState != null)
            {
                WindowStateChanged?.Invoke(this, EventArgs.Empty);
            }
        }