/// <summary> /// Get preferred size. /// </summary> /// <param name="proposedSize">Proposed size.</param> /// <returns>Preferred size.</returns> public override Size GetPreferredSize(Size proposedSize) { Size preferredSize; base.GetPreferredSize(proposedSize); using (var g = CreateGraphics()) { string measureText = Text.Length > 0 ? Text : "MeasureText"; proposedSize = new Size(int.MaxValue, int.MaxValue); preferredSize = TextRenderer.MeasureText(g, measureText, ModernFonts.DateTime(this.FontSize, this.FontWeight), proposedSize, TextFormatFlags.Left | TextFormatFlags.LeftAndRightPadding | TextFormatFlags.VerticalCenter); preferredSize.Height += 10; } return(preferredSize); }
/// <summary> /// OnPaintForeground method. /// </summary> /// <param name="e">PaintEventArgs instance.</param> protected virtual void OnPaintForeground(PaintEventArgs e) { this.MinimumSize = new Size(0, this.GetPreferredSize(Size.Empty).Height); Color borderColor; Color foreColor; if (this._isHovered && !this._isPressed && this.Enabled) { foreColor = ModernPaint.ForeColor.ComboBox.Hover(this.ThemeStyle); borderColor = ModernPaint.GetStyleColor(this.ColorStyle); } else if (this._isHovered && this._isPressed && this.Enabled) { foreColor = ModernPaint.ForeColor.ComboBox.Press(this.ThemeStyle); borderColor = ModernPaint.GetStyleColor(this.ColorStyle); } else if (!this.Enabled) { foreColor = ModernPaint.ForeColor.ComboBox.Disabled(this.ThemeStyle); borderColor = ModernPaint.BorderColor.ComboBox.Disabled(this.ThemeStyle); } else { foreColor = ModernPaint.ForeColor.ComboBox.Normal(this.ThemeStyle); borderColor = ModernPaint.BorderColor.ComboBox.Normal(this.ThemeStyle); } using (Pen pen = new Pen(borderColor)) { Rectangle boxRectangle = new Rectangle(0, 0, this.Width - 1, this.Height - 1); e.Graphics.DrawRectangle(pen, boxRectangle); } using (SolidBrush brush = new SolidBrush(foreColor)) { e.Graphics.FillPolygon(brush, new Point[] { new Point(this.Width - 20, (this.Height / 2) - 2), new Point(this.Width - 9, (this.Height / 2) - 2), new Point(this.Width - 15, (this.Height / 2) + 4) }); } int check = 0; if (this.ShowCheckBox) { check = 15; using (Pen pen = new Pen(borderColor)) { Rectangle boxRectangle = new Rectangle(3, (this.Height / 2) - 6, 12, 12); e.Graphics.DrawRectangle(pen, boxRectangle); } if (this.Checked) { Color fillColor = ModernPaint.GetStyleColor(this.ColorStyle); using (SolidBrush brush = new SolidBrush(fillColor)) { Rectangle boxRectangle = new Rectangle(5, (this.Height / 2) - 4, 9, 9); e.Graphics.FillRectangle(brush, boxRectangle); } } else { foreColor = ModernPaint.ForeColor.ComboBox.Disabled(this.ThemeStyle); } } Rectangle textRectangle = new Rectangle(2 + check, 2, this.Width - 20, this.Height - 4); TextRenderer.DrawText(e.Graphics, this.Text, ModernFonts.DateTime(this.FontSize, this.FontWeight), textRectangle, foreColor, TextFormatFlags.Left | TextFormatFlags.VerticalCenter); this.OnCustomPaintForeground(new ModernPaintEventArgs(Color.Empty, foreColor, e.Graphics)); if (this.DisplayFocus && this._isFocused) { ControlPaint.DrawFocusRectangle(e.Graphics, this.ClientRectangle); } }