protected override void Draw(bool fillContent) { base.Draw(fillContent); using (var g = Graphics.FromHwnd(this.Handle)) { Rectangle rect = StiControlPaint.GetContentRect(new Rectangle(0, 0, Width - 1, Height - 1), true, RightToLeft); rect.Inflate(-2, -2); //rect.Width--; rect.Height++; var args = new DrawItemEventArgs(g, Font, rect, -1, Focused ? DrawItemState.Selected : DrawItemState.Default); drawCombo = true; OnDrawItem(args); drawCombo = false; } }
protected override Rectangle GetContentRect() { Rectangle contentRect = StiControlPaint.GetContentRect(this.ClientRectangle, Flat, RightToLeft); Rectangle buttonRect = GetButtonRect(this.ClientRectangle); buttonRect.Width += 2; contentRect.Width -= (buttonRect.Width - SystemInformation.HorizontalScrollBarArrowWidth + SystemInformation.Border3DSize.Width); if (ButtonAlign == StiButtonAlign.Right) { contentRect.X += 2; return(contentRect); } else { contentRect.X += buttonRect.Width; return(contentRect); } }
protected override void OnPaint(PaintEventArgs p) { base.OnPaint(p); Graphics g = p.Graphics; Rectangle colorRect = Rectangle.Empty; Rectangle textRect = Rectangle.Empty; Rectangle buttonRect = StiControlPaint.GetButtonRect(this.ClientRectangle, true, RightToLeft); Rectangle contentRect = StiControlPaint.GetContentRect(this.ClientRectangle, true, RightToLeft); Rectangle rect = new Rectangle(0, 0, Width - 1, Height - 1); if (showColorBox) { if (showColorName) { colorRect = new Rectangle(rect.X + 4, rect.Y + 4, 22, Height - 9); if (RightToLeft == RightToLeft.Yes) { colorRect.X = rect.Width - colorRect.Width - 4; } } else { colorRect = new Rectangle(rect.X + 4, rect.Y + 4, Width - buttonRect.Width - 10, Height - 9); if (RightToLeft == RightToLeft.Yes) { colorRect.X = rect.Width - colorRect.Width - 4; } } } if (showColorName) { if (showColorBox) { textRect = new Rectangle(colorRect.Right + 2, 1, Width - colorRect.Width - buttonRect.Width - 4, Height - 2); if (RightToLeft == RightToLeft.Yes) { textRect.X = contentRect.X - 4; } } else { textRect = new Rectangle(2, 1, Width - buttonRect.Width - 2, Height - 2); if (RightToLeft == RightToLeft.Yes) { textRect.X = contentRect.X - 4; } } } #region Paint focus if (this.Focused) { Rectangle focusRect = GetContentRect(); focusRect.X -= 1; focusRect.Y += 1; focusRect.Width--; focusRect.Height -= 2; ControlPaint.DrawFocusRectangle(g, focusRect); } #endregion #region Paint color if (showColorBox) { using (var brush = new SolidBrush(SelectedColor)) g.FillRectangle(brush, colorRect); if (this.Enabled) { g.DrawRectangle(Pens.Black, colorRect); } else { g.DrawRectangle(SystemPens.ControlDark, colorRect); } } #endregion #region Paint color name if (showColorName) { using (var sf = new StringFormat()) { sf.LineAlignment = StringAlignment.Center; sf.FormatFlags = StringFormatFlags.NoWrap; if (this.RightToLeft == RightToLeft.Yes) { sf.FormatFlags |= StringFormatFlags.DirectionRightToLeft; } string colorName = null; if (SelectedColor.IsSystemColor) { colorName = StiLocalization.Get("PropertySystemColors", SelectedColor.Name); } else if (SelectedColor.IsKnownColor) { colorName = StiLocalization.Get("PropertyColor", SelectedColor.Name); } else { colorName = StiLocalization.Get("FormColorBoxPopup", "Color") + "[A=" + SelectedColor.A.ToString() + ", R=" + SelectedColor.R.ToString() + ", G=" + SelectedColor.G.ToString() + ", B=" + SelectedColor.B.ToString() + "]"; } if (this.Enabled) { using (var brush = new SolidBrush(this.ForeColor)) { g.DrawString(colorName, Font, brush, textRect, sf); } } else { g.DrawString(colorName, Font, SystemBrushes.ControlDark, textRect, sf); } } } #endregion }
public static void DrawNumericUpDown(Graphics g, Rectangle rect, string text, Font font, Color foreColor, Color backColor, RightToLeft rightToLeft, bool isEnabled, bool readOnly, bool isMouseOver, bool isUpMouseOver, bool isDownMouseOver, bool isUpPressed, bool isDownPressed, bool isFocused, bool flat, bool fillContent, Bitmap buttonUpBitmap, Bitmap buttonDownBitmap) { if (isEnabled) { text = string.Empty; } if (fillContent) { using (var brush = new SolidBrush(backColor)) { g.FillRectangle(brush, rect); } } if (!isEnabled) { using (var brush = new SolidBrush(SystemColors.Control)) { var rcContent = rect; rcContent.X += 2; rcContent.Y += 2; rcContent.Height -= 3; rcContent.Width -= 2; g.FillRectangle(brush, rcContent); } } var upButtonRect = GetUpButtonRect(rect, flat, rightToLeft); var downButtonRect = GetDownButtonRect(rect, flat, rightToLeft); var contentRect = StiControlPaint.GetContentRect(rect, flat, rightToLeft); contentRect.Height++; if (readOnly) { isMouseOver = false; } StiControlPaint.DrawBorder(g, rect, isMouseOver | isFocused, flat); #region Paint up button Color color = SystemColors.ControlDark; if (isUpMouseOver) { color = StiColors.SelectedText; } if (buttonUpBitmap != null && buttonDownBitmap != null) { StiControlPaint.DrawButton(g, upButtonRect, buttonUpBitmap, isUpPressed, isUpMouseOver | isFocused, isUpMouseOver, isEnabled, flat); } #endregion #region Paint down button color = SystemColors.ControlDark; if (isDownMouseOver) { color = StiColors.SelectedText; } if (buttonUpBitmap != null && buttonDownBitmap != null) { StiControlPaint.DrawButton(g, downButtonRect, buttonDownBitmap, isDownPressed, isDownMouseOver | isFocused, isDownMouseOver, isEnabled, flat); } #endregion if (text != null) { Color textColor = foreColor; if (!isEnabled) { textColor = SystemColors.ControlDark; } using (var sf = new StringFormat()) using (var brush = new SolidBrush(textColor)) { sf.FormatFlags = StringFormatFlags.NoWrap; sf.LineAlignment = StringAlignment.Center; g.DrawString(text, font, brush, rect, sf); } } if (isMouseOver) { g.DrawRectangle(StiPens.SelectedText, rect); } }