예제 #1
0
        private void UpdateButtons(MouseEventArgs e, Boolean up = false)
        {
            if (DesignMode)
            {
                return;
            }
            var     oldState = _buttonState;
            Boolean showMin  = MinimizeBox && ControlBox;
            Boolean showMax  = MaximizeBox && ControlBox;

            if (e.Button == MouseButtons.Left && !up)
            {
                if (showMin && !showMax && ButtonShow_Bounds.Contains(e.Location))
                {
                    _buttonState = ButtonState.ButtonHide_Down;
                }
                else if (showMin && showMax && ButtonHide_Bounds.Contains(e.Location))
                {
                    _buttonState = ButtonState.ButtonHide_Down;
                }
                else if (showMax && ButtonShow_Bounds.Contains(e.Location))
                {
                    _buttonState = ButtonState.ButtonShow_Down;
                }
                else if (ControlBox && ButtonClose_Bounds.Contains(e.Location))
                {
                    _buttonState = ButtonState.ButtonClose_Down;
                }
                else
                {
                    _buttonState = ButtonState.None;
                }
            }
            else
            {
                if (showMin && !showMax && ButtonShow_Bounds.Contains(e.Location))
                {
                    _buttonState = ButtonState.ButtonHide_Over;

                    if (oldState == ButtonState.ButtonHide_Down && up)
                    {
                        Animation("HIDE", 5);
                    }
                    //WindowState = FormWindowState.Minimized;
                }
                else if (showMin && showMax && ButtonHide_Bounds.Contains(e.Location))
                {
                    _buttonState = ButtonState.ButtonHide_Over;

                    if (oldState == ButtonState.ButtonHide_Down && up)
                    {
                        Animation("HIDE", 5);
                    }
                    //WindowState = FormWindowState.Minimized;
                }
                else if (MaximizeBox && ControlBox && ButtonShow_Bounds.Contains(e.Location))
                {
                    _buttonState = ButtonState.ButtonShow_Over;

                    if (oldState == ButtonState.ButtonShow_Down && up)
                    {
                        MaximizeWindow(!_maximized);
                    }
                }
                else if (ControlBox && ButtonClose_Bounds.Contains(e.Location))
                {
                    _buttonState = ButtonState.ButtonClose_Over;

                    if (oldState == ButtonState.ButtonClose_Down && up)
                    {
                        Animation("EXIT", 5);
                    }
                    //Close();
                }
                else
                {
                    _buttonState = ButtonState.None;
                }
            }

            if (oldState != _buttonState)
            {
                Invalidate();
            }
        }
예제 #2
0
        protected override void WndProc(ref Message e)
        {
            if (e.Msg == 70)
            {
                Rectangle WorkingArea = SystemInformation.WorkingArea;
                Rectangle Rectangle   = (Rectangle)System.Runtime.InteropServices.Marshal.PtrToStructure((IntPtr)((long)(IntPtr.Size * 2) + e.LParam.ToInt64()), typeof(Rectangle));
                if (Rectangle.X <= WorkingArea.Left + 10)
                {
                    Marshal.WriteInt32(e.LParam, IntPtr.Size * 2, WorkingArea.Left);
                }
                if (Rectangle.X + Rectangle.Width >= WorkingArea.Width - 10)
                {
                    Marshal.WriteInt32(e.LParam, IntPtr.Size * 2, WorkingArea.Right - Rectangle.Width);
                }
                if (Rectangle.Y <= WorkingArea.Top + 10)
                {
                    Marshal.WriteInt32(e.LParam, IntPtr.Size * 2 + 4, WorkingArea.Top);
                }
                if (Rectangle.Y + Rectangle.Height >= WorkingArea.Height - 10)
                {
                    Marshal.WriteInt32(e.LParam, IntPtr.Size * 2 + 4, WorkingArea.Bottom - Rectangle.Height);
                }
            }

            base.WndProc(ref e);

            if (DesignMode || IsDisposed)
            {
                return;
            }

            if (e.Msg == 0x0203)
            {
                MaximizeWindow(!_maximized);
            }
            else
            if (e.Msg == 0x0200 && _maximized &&
                !(ButtonHide_Bounds.Contains(PointToClient(Cursor.Position)) || ButtonShow_Bounds.Contains(PointToClient(Cursor.Position)) || ButtonClose_Bounds.Contains(PointToClient(Cursor.Position))))
            {
                if (_headerMouseDown)
                {
                    _maximized       = false;
                    _headerMouseDown = false;

                    Point mousePoint = PointToClient(Cursor.Position);
                    if (mousePoint.X < Width / 2)
                    {
                        Location = mousePoint.X < _previousSize.Width / 2 ?
                                   new Point(Cursor.Position.X - mousePoint.X, Cursor.Position.Y - mousePoint.Y) :
                                   new Point(Cursor.Position.X - _previousSize.Width / 2, Cursor.Position.Y - mousePoint.Y);
                    }
                    else
                    {
                        Location = Width - mousePoint.X < _previousSize.Width / 2 ?
                                   new Point(Cursor.Position.X - _previousSize.Width + Width - mousePoint.X, Cursor.Position.Y - mousePoint.Y) :
                                   new Point(Cursor.Position.X - _previousSize.Width / 2, Cursor.Position.Y - mousePoint.Y);
                    }

                    Size = _previousSize;
                    ReleaseCapture();
                    SendMessage(Handle, 0xA1, 0x2, 0);
                }
            }
            else
            if (e.Msg == 0x0201 &&
                !(ButtonHide_Bounds.Contains(PointToClient(Cursor.Position)) || ButtonShow_Bounds.Contains(PointToClient(Cursor.Position)) || ButtonClose_Bounds.Contains(PointToClient(Cursor.Position))))
            {
                if (!_maximized)
                {
                    ReleaseCapture();
                    SendMessage(Handle, 0xA1, 0x2, 0);
                }
                else
                {
                    _headerMouseDown = true;
                }
            }
            else
            if (e.Msg == 0x0204)
            {
                Point cursorPos = PointToClient(Cursor.Position);

                if (StatusBar_Bounds.Contains(cursorPos) && !ButtonHide_Bounds.Contains(cursorPos) &&
                    !ButtonShow_Bounds.Contains(cursorPos) && !ButtonClose_Bounds.Contains(cursorPos))
                {
                    // Показывать системное меню по умолчанию при щелчке правой кнопкой мыши
                    var id = TrackPopupMenuEx(GetSystemMenu(Handle, false), 0x0000 | 0x0100, Cursor.Position.X, Cursor.Position.Y, Handle, IntPtr.Zero);

                    // Передайте команду в виде сообщения WM_SYSCOMMAND
                    SendMessage(Handle, 0x0112, id, 0);
                }
            }
            else
            if (e.Msg == 0xA1)
            {
                // Это повторно включает изменение размера, позволяя приложению знать, когда
                // пользователь пытается изменить размер стороны. По умолчанию эта функция отключена при использовании WS_SYSMENU.
                if (!Sizable)
                {
                    return;
                }

                byte bFlag = 0;

                // Вам какую сторону изменяется от
                if (_resizingLocationsToCmd.ContainsKey((Int32)e.WParam))
                {
                    bFlag = (byte)_resizingLocationsToCmd[(Int32)e.WParam];
                }

                if (bFlag != 0)
                {
                    SendMessage(Handle, 0x0112, 0xF000 | bFlag, (Int32)e.LParam);
                }
            }
            else
            if (e.Msg == 0x0202)
            {
                _headerMouseDown = false;
            }
        }