예제 #1
0
            private void DrawUpDownButton()
            {
                bool mouseOver       = false;
                bool mousePress      = LeftKeyPressed();
                bool mouseInUpButton = false;

                Rectangle clipRect = _upDownButton.ClientRectangle;

                RECT  windowRect  = new RECT();
                Point cursorPoint = new Point();

                GetCursorPos(ref cursorPoint);
                GetWindowRect(_upDownButtonWnd, ref windowRect);

                mouseOver = PtInRect(ref windowRect, cursorPoint);

                cursorPoint.X -= windowRect.Left;
                cursorPoint.Y -= windowRect.Top;

                mouseInUpButton = cursorPoint.Y < clipRect.Height / 2;

                using (Graphics g = Graphics.FromHwnd(_upDownButtonWnd))
                {
                    UpDownButtonPaintEventArgs e =
                        new UpDownButtonPaintEventArgs(
                            g,
                            clipRect,
                            mouseOver,
                            mousePress,
                            mouseInUpButton);
                    _owner.OnPaintUpDownButton(e);
                }
            }
예제 #2
0
            private void DrawUpDownButton()
            {
                bool mouseOver       = false;
                bool mousePress      = LeftKeyPressed();
                bool mouseInUpButton = false;

                NativeMethods.RECT rect = new NativeMethods.RECT();

                NativeMethods.GetClientRect(base.Handle, ref rect);

                Rectangle clipRect = Rectangle.FromLTRB(
                    rect.Top, rect.Left, rect.Right, rect.Bottom);

                Point cursorPoint = new Point();

                NativeMethods.GetCursorPos(ref cursorPoint);
                NativeMethods.GetWindowRect(base.Handle, ref rect);

                mouseOver = NativeMethods.PtInRect(ref rect, cursorPoint);

                cursorPoint.X -= rect.Left;
                cursorPoint.Y -= rect.Top;

                mouseInUpButton = cursorPoint.X < clipRect.Width / 2;

                using (Graphics g = Graphics.FromHwnd(base.Handle))
                {
                    UpDownButtonPaintEventArgs e =
                        new UpDownButtonPaintEventArgs(
                            g,
                            clipRect,
                            mouseOver,
                            mousePress,
                            mouseInUpButton);
                    _owner.OnPaintUpDownButton(e);
                }
            }
예제 #3
0
        protected virtual void OnPaintUpDownButton(
            UpDownButtonPaintEventArgs e)
        {
            Graphics  g    = e.Graphics;
            Rectangle rect = e.ClipRectangle;

            Color upButtonBaseColor   = _baseColor;
            Color upButtonBorderColor = _borderColor;
            Color upButtonArrowColor  = _arrowColor;

            Color downButtonBaseColor   = _baseColor;
            Color downButtonBorderColor = _borderColor;
            Color downButtonArrowColor  = _arrowColor;

            Rectangle upButtonRect = rect;

            upButtonRect.Y     += 1;
            upButtonRect.Width -= 2;
            upButtonRect.Height = rect.Height / 2 - 2;

            Rectangle downButtonRect = rect;

            downButtonRect.Y      = upButtonRect.Bottom + 2;
            downButtonRect.Height = rect.Height - upButtonRect.Bottom - 4;
            downButtonRect.Width -= 2;

            if (Enabled)
            {
                if (e.MouseOver)
                {
                    if (e.MousePress)
                    {
                        if (e.MouseInUpButton)
                        {
                            upButtonBaseColor = ColorClass.GetColor(_baseColor, 0, -35, -24, -9);
                        }
                        else
                        {
                            downButtonBaseColor = ColorClass.GetColor(_baseColor, 0, -35, -24, -9);
                        }
                    }
                    else
                    {
                        if (e.MouseInUpButton)
                        {
                            upButtonBaseColor = ColorClass.GetColor(_baseColor, 0, 35, 24, 9);
                        }
                        else
                        {
                            downButtonBaseColor = ColorClass.GetColor(_baseColor, 0, 35, 24, 9);
                        }
                    }
                }
            }
            else
            {
                upButtonBaseColor   = SystemColors.Control;
                upButtonBorderColor = SystemColors.ControlDark;
                upButtonArrowColor  = SystemColors.ControlDark;

                downButtonBaseColor   = SystemColors.Control;
                downButtonBorderColor = SystemColors.ControlDark;
                downButtonArrowColor  = SystemColors.ControlDark;
            }

            g.SmoothingMode = SmoothingMode.AntiAlias;

            Color backColor = Enabled ? base.BackColor : SystemColors.Control;

            using (SolidBrush brush = new SolidBrush(backColor))
            {
                rect.Inflate(1, 1);
                g.FillRectangle(brush, rect);
            }

            RenderButton(
                g,
                upButtonRect,
                upButtonBaseColor,
                upButtonBorderColor,
                upButtonArrowColor,
                ArrowDirection.Up);
            RenderButton(
                g,
                downButtonRect,
                downButtonBaseColor,
                downButtonBorderColor,
                downButtonArrowColor,
                ArrowDirection.Down);

            UpDownButtonPaintEventHandler handler =
                base.Events[EventPaintUpDownButton] as UpDownButtonPaintEventHandler;

            if (handler != null)
            {
                handler(this, e);
            }
        }