Beispiel #1
0
    protected override void OnMouseUp(System.Windows.Forms.MouseEventArgs e)
    {
        if (IntersectsWithRect(ref e, ref rectMinimize))
        {
            CurPos2 = rectMinimize;
        }
        else
        if (IntersectsWithRect(ref e, ref rectMaximize))
        {
            CurPos2 = rectMaximize;
        }
        else
        if (IntersectsWithRect(ref e, ref rectExit))
        {
            CurPos2 = rectExit;
        }
        if (!resizeInfo.Activated && CurPos1 == CurPos2)
        {
            switch (HoverState)
            {
            case Hoverbutton.Exit_:
                this.Close();
                break;

            case Hoverbutton.Maximize:
                if (WindowState == FormWindowState.Maximized)
                {
                    WindowState = FormWindowState.Normal;
                    this.Invalidate();
                }
                else
                {
                    Rectangle rect = new Rectangle(0, 0, this.Width, this.Height);
                    WindowState = FormWindowState.Maximized;
                    this.Invalidate(rect);
                }
                break;

            case Hoverbutton.Minimize:
                WindowState = FormWindowState.Minimized;
                break;
            }
            HoverState = Hoverbutton.None;
            //OnMouseMove(e)
        }
        base.OnMouseUp(e);
        resizeInfo.Activated = false;
        Cursor = Cursors.Default;
        OnMouseMove(e);
    }
Beispiel #2
0
    private void InvalidateButton(Hoverbutton state)
    {
        switch (state)
        {
        case Hoverbutton.Maximize:
            Invalidate(rectMaximize);
            break;

        case Hoverbutton.Minimize:
            Invalidate(rectMinimize);
            break;

        case Hoverbutton.Exit_:
            Invalidate(rectExit);
            break;
        }
    }
Beispiel #3
0
    private void UpdatePrevious()
    {
        Hoverbutton previous = HoverState;

        HoverState = Hoverbutton.None;
        switch (previous)
        {
        case Hoverbutton.Maximize:
            this.Invalidate(rectMaximize);
            break;

        case Hoverbutton.Minimize:
            this.Invalidate(rectMinimize);
            break;

        case Hoverbutton.Exit_:
            this.Invalidate(rectExit);
            break;
        }
    }
Beispiel #4
0
    // Implementation of events

    protected override void OnMouseMove(System.Windows.Forms.MouseEventArgs e)
    {
        base.OnMouseMove(e);
        if (this.ControlBox & !resizeInfo.Activated)
        {
            //Exit button
            if (IntersectsWithRect(ref e, ref rectExit))
            {
                if (HoverState != Hoverbutton.Exit_)
                {
                    Hoverbutton previous = HoverState;
                    HoverState = Hoverbutton.Exit_;
                    InvalidateButton(previous);
                    this.Invalidate(rectExit);
                }
            }
            else if (this.MaximizeBox && IntersectsWithRect(ref e, ref rectMaximize))
            {
                if (HoverState != Hoverbutton.Maximize)
                {
                    Hoverbutton previous = HoverState;
                    HoverState = Hoverbutton.Maximize;
                    InvalidateButton(previous);
                    this.Invalidate(rectMaximize);
                }
            }
            else if (this.MinimizeBox && IntersectsWithRect(ref e, ref rectMinimize))
            {
                if (HoverState != Hoverbutton.Minimize)
                {
                    Hoverbutton previous = HoverState;
                    HoverState = Hoverbutton.Minimize;
                    InvalidateButton(previous);
                    this.Invalidate(rectMinimize);
                }
            }
            else
            {
                if (HoverState != Hoverbutton.None)
                {
                    UpdatePrevious();
                }
            }
        }

        //change cursor icon and do resize
        if (WindowState == FormWindowState.Normal && _CanResize)
        {
            resizeInfo.Activated = true;
            if (IntersectsWithRect(ref e, ref rectResizeBottomRight))
            {
                Cursor          = Cursors.SizeNWSE;
                resizeInfo.Mode = ResizeMode.BottomRight;
            }
            else if (IntersectsWithRect(ref e, ref rectResizeBottomLeft))
            {
                Cursor          = Cursors.SizeNESW;
                resizeInfo.Mode = ResizeMode.BottomLeft;
            }
            else if (IntersectsWithRect(ref e, ref rectResizeTopLeft))
            {
                Cursor          = Cursors.SizeNWSE;
                resizeInfo.Mode = ResizeMode.TopLeft;
            }
            else if (IntersectsWithRect(ref e, ref rectResizeTopRight))
            {
                Cursor          = Cursors.SizeNESW;
                resizeInfo.Mode = ResizeMode.TopRight;
            }
            else if (IntersectsWithRect(ref e, ref rectResizeRight))
            {
                Cursor          = Cursors.SizeWE;
                resizeInfo.Mode = ResizeMode.Right;
            }
            else if (IntersectsWithRect(ref e, ref rectResizeLeft))
            {
                Cursor          = Cursors.SizeWE;
                resizeInfo.Mode = ResizeMode.Left;
            }
            else if (IntersectsWithRect(ref e, ref rectResizeBottom))
            {
                Cursor          = Cursors.SizeNS;
                resizeInfo.Mode = ResizeMode.Bottom;
            }
            else if (IntersectsWithRect(ref e, ref rectResizeTop))
            {
                Cursor          = Cursors.SizeNS;
                resizeInfo.Mode = ResizeMode.Top;
            }
            else
            {
                Cursor = Cursors.Default;
                resizeInfo.Activated = false;
            }
        }
    }