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); } }
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 = GetColor(_baseColor, 0, -35, -24, -9); } else { downButtonBaseColor = GetColor(_baseColor, 0, -35, -24, -9); } } else { if (e.MouseInUpButton) { upButtonBaseColor = GetColor(_baseColor, 0, 35, 24, 9); } else { downButtonBaseColor = 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(base.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); } }