public override System.Drawing.Size GetPreferredSize(System.Drawing.Size proposedSize) { System.Drawing.Size width; base.GetPreferredSize(proposedSize); using (Graphics graphic = base.CreateGraphics()) { proposedSize = new System.Drawing.Size(2147483647, 2147483647); width = TextRenderer.MeasureText(graphic, this.Text, MetroFonts.CheckBox(this.metroCheckBoxSize, this.metroCheckBoxWeight), proposedSize, MetroPaint.GetTextFormatFlags(this.TextAlign)); width.Width = width.Width + 16; } return(width); }
public override Size GetPreferredSize(Size proposedSize) { Size preferredSize; base.GetPreferredSize(proposedSize); using (var g = CreateGraphics()) { proposedSize = new Size(int.MaxValue, int.MaxValue); preferredSize = TextRenderer.MeasureText(g, Text, MetroFonts.CheckBox(metroCheckBoxSize, metroCheckBoxWeight), proposedSize, MetroPaint.GetTextFormatFlags(TextAlign)); preferredSize.Width += 16; } return(preferredSize); }
protected virtual void OnPaintForeground(PaintEventArgs e) { Color color; Color foreColor; if (this.useCustomForeColor) { foreColor = this.ForeColor; if (this.isHovered && !this.isPressed && base.Enabled) { color = MetroPaint.BorderColor.CheckBox.Hover(this.Theme); } else if (!this.isHovered || !this.isPressed || !base.Enabled) { color = (base.Enabled ? MetroPaint.BorderColor.CheckBox.Normal(this.Theme) : MetroPaint.BorderColor.CheckBox.Disabled(this.Theme)); } else { color = MetroPaint.BorderColor.CheckBox.Press(this.Theme); } } else if (this.isHovered && !this.isPressed && base.Enabled) { foreColor = MetroPaint.ForeColor.CheckBox.Hover(this.Theme); color = MetroPaint.BorderColor.CheckBox.Hover(this.Theme); } else if (this.isHovered && this.isPressed && base.Enabled) { foreColor = MetroPaint.ForeColor.CheckBox.Press(this.Theme); color = MetroPaint.BorderColor.CheckBox.Press(this.Theme); } else if (base.Enabled) { foreColor = (!this.useStyleColors ? MetroPaint.ForeColor.CheckBox.Normal(this.Theme) : MetroPaint.GetStyleColor(this.Style)); color = MetroPaint.BorderColor.CheckBox.Normal(this.Theme); } else { foreColor = MetroPaint.ForeColor.CheckBox.Disabled(this.Theme); color = MetroPaint.BorderColor.CheckBox.Disabled(this.Theme); } Rectangle rectangle = new Rectangle(16, 0, base.Width - 16, base.Height); Rectangle rectangle1 = new Rectangle(0, base.Height / 2 - 6, 12, 12); using (Pen pen = new Pen(color)) { ContentAlignment checkAlign = base.CheckAlign; if (checkAlign <= ContentAlignment.MiddleCenter) { switch (checkAlign) { case ContentAlignment.TopLeft: { rectangle1 = new Rectangle(0, 0, 12, 12); break; } case ContentAlignment.TopCenter: { rectangle1 = new Rectangle(base.Width / 2 - 6, 0, 12, 12); rectangle = new Rectangle(16, rectangle1.Top + rectangle1.Height - 5, base.Width - 8, base.Height); break; } case ContentAlignment.TopLeft | ContentAlignment.TopCenter: { break; } case ContentAlignment.TopRight: { rectangle1 = new Rectangle(base.Width - 13, 0, 12, 12); rectangle = new Rectangle(0, 0, base.Width - 16, base.Height); break; } default: { if (checkAlign == ContentAlignment.MiddleLeft) { rectangle1 = new Rectangle(0, base.Height / 2 - 6, 12, 12); break; } else if (checkAlign == ContentAlignment.MiddleCenter) { rectangle1 = new Rectangle(base.Width / 2 - 6, base.Height / 2 - 6, 12, 12); break; } else { break; } } } } else if (checkAlign <= ContentAlignment.BottomLeft) { if (checkAlign == ContentAlignment.MiddleRight) { rectangle1 = new Rectangle(base.Width - 13, base.Height / 2 - 6, 12, 12); rectangle = new Rectangle(0, 0, base.Width - 16, base.Height); } else if (checkAlign == ContentAlignment.BottomLeft) { rectangle1 = new Rectangle(0, base.Height - 13, 12, 12); } } else if (checkAlign == ContentAlignment.BottomCenter) { rectangle1 = new Rectangle(base.Width / 2 - 6, base.Height - 13, 12, 12); rectangle = new Rectangle(16, -10, base.Width - 8, base.Height); } else if (checkAlign == ContentAlignment.BottomRight) { rectangle1 = new Rectangle(base.Width - 13, base.Height - 13, 12, 12); rectangle = new Rectangle(0, 0, base.Width - 16, base.Height); } e.Graphics.DrawRectangle(pen, rectangle1); } if (base.Checked) { using (SolidBrush solidBrush = new SolidBrush((base.CheckState == System.Windows.Forms.CheckState.Indeterminate ? color : MetroPaint.GetStyleColor(this.Style)))) { Rectangle rectangle2 = new Rectangle(rectangle1.Left + 2, rectangle1.Top + 2, 9, 9); e.Graphics.FillRectangle(solidBrush, rectangle2); } } TextRenderer.DrawText(e.Graphics, this.Text, MetroFonts.CheckBox(this.metroCheckBoxSize, this.metroCheckBoxWeight), rectangle, foreColor, MetroPaint.GetTextFormatFlags(this.TextAlign)); this.OnCustomPaintForeground(new MetroPaintEventArgs(Color.Empty, foreColor, e.Graphics)); if (this.displayFocusRectangle && this.isFocused) { ControlPaint.DrawFocusRectangle(e.Graphics, base.ClientRectangle); } }
protected virtual void OnPaintForeground(PaintEventArgs e) { Color borderColor, foreColor; if (useCustomForeColor) { foreColor = ForeColor; if (isHovered && !isPressed && Enabled) { borderColor = MetroPaint.BorderColor.CheckBox.Hover(Theme); } else if (isHovered && isPressed && Enabled) { borderColor = MetroPaint.BorderColor.CheckBox.Press(Theme); } else if (!Enabled) { borderColor = MetroPaint.BorderColor.CheckBox.Disabled(Theme); } else { borderColor = MetroPaint.BorderColor.CheckBox.Normal(Theme); } } else { if (isHovered && !isPressed && Enabled) { foreColor = MetroPaint.ForeColor.CheckBox.Hover(Theme); borderColor = MetroPaint.BorderColor.CheckBox.Hover(Theme); } else if (isHovered && isPressed && Enabled) { foreColor = MetroPaint.ForeColor.CheckBox.Press(Theme); borderColor = MetroPaint.BorderColor.CheckBox.Press(Theme); } else if (!Enabled) { foreColor = MetroPaint.ForeColor.CheckBox.Disabled(Theme); borderColor = MetroPaint.BorderColor.CheckBox.Disabled(Theme); } else { foreColor = !useStyleColors?MetroPaint.ForeColor.CheckBox.Normal(Theme) : MetroPaint.GetStyleColor(Style); borderColor = MetroPaint.BorderColor.CheckBox.Normal(Theme); } } using (Pen p = new Pen(borderColor)) { Rectangle boxRect = new Rectangle(0, Height / 2 - 6, 12, 12); e.Graphics.DrawRectangle(p, boxRect); } if (Checked) { Color fillColor = CheckState == CheckState.Indeterminate ? borderColor : MetroPaint.GetStyleColor(Style); using (SolidBrush b = new SolidBrush(fillColor)) { Rectangle boxRect = new Rectangle(2, Height / 2 - 4, 9, 9); e.Graphics.FillRectangle(b, boxRect); } } Rectangle textRect = new Rectangle(16, 0, Width - 16, Height); TextRenderer.DrawText(e.Graphics, Text, MetroFonts.CheckBox(metroCheckBoxSize, metroCheckBoxWeight), textRect, foreColor, MetroPaint.GetTextFormatFlags(TextAlign)); OnCustomPaintForeground(new MetroPaintEventArgs(Color.Empty, foreColor, e.Graphics)); if (displayFocusRectangle && isFocused) { ControlPaint.DrawFocusRectangle(e.Graphics, ClientRectangle); } }
protected virtual void OnPaintForeground(PaintEventArgs e) { Color borderColor, foreColor; if (useCustomForeColor) { foreColor = ForeColor; if (isHovered && !isPressed && Enabled) { borderColor = ForeColor;// MetroPaint.BorderColor.CheckBox.Hover(Theme); } else if (isHovered && isPressed && Enabled) { borderColor = MetroPaint.BorderColor.CheckBox.Press(Theme); } else if (!Enabled) { borderColor = MetroPaint.BorderColor.CheckBox.Disabled(Theme); } else { borderColor = MetroPaint.BorderColor.CheckBox.Normal(Theme); } } else { if (isHovered && !isPressed && Enabled) { foreColor = MetroPaint.ForeColor.CheckBox.Hover(Theme); borderColor = MetroPaint.BorderColor.CheckBox.Hover(Theme); } else if (isHovered && isPressed && Enabled) { foreColor = MetroPaint.ForeColor.CheckBox.Press(Theme); borderColor = MetroPaint.BorderColor.CheckBox.Press(Theme); } else if (!Enabled) { foreColor = MetroPaint.ForeColor.CheckBox.Disabled(Theme); borderColor = MetroPaint.BorderColor.CheckBox.Disabled(Theme); } else { foreColor = !useStyleColors?MetroPaint.ForeColor.CheckBox.Normal(Theme) : MetroPaint.GetStyleColor(Style); borderColor = MetroPaint.BorderColor.CheckBox.Normal(Theme); } } Rectangle textRect = new Rectangle(16, 0, Width - 16, Height); Rectangle boxRect = new Rectangle(0, Height / 2 - 6, 12, 12); using (Pen p = new Pen(borderColor)) { switch (CheckAlign) { case ContentAlignment.TopLeft: boxRect = new Rectangle(0, 0, 12, 12); break; case ContentAlignment.MiddleLeft: boxRect = new Rectangle(0, Height / 2 - 6, 12, 12); break; case ContentAlignment.BottomLeft: boxRect = new Rectangle(0, Height - 13, 12, 12); break; case ContentAlignment.TopCenter: boxRect = new Rectangle(Width / 2 - 6, 0, 12, 12); textRect = new Rectangle(16, boxRect.Top + boxRect.Height - 5, Width - 16 / 2, Height); break; case ContentAlignment.BottomCenter: boxRect = new Rectangle(Width / 2 - 6, Height - 13, 12, 12); textRect = new Rectangle(16, -10, Width - 16 / 2, Height); break; case ContentAlignment.MiddleCenter: boxRect = new Rectangle(Width / 2 - 6, Height / 2 - 6, 12, 12); break; case ContentAlignment.TopRight: boxRect = new Rectangle(Width - 13, 0, 12, 12); textRect = new Rectangle(0, 0, Width - 16, Height); break; case ContentAlignment.MiddleRight: boxRect = new Rectangle(Width - 13, Height / 2 - 6, 12, 12); textRect = new Rectangle(0, 0, Width - 16, Height); break; case ContentAlignment.BottomRight: boxRect = new Rectangle(Width - 13, Height - 13, 12, 12); textRect = new Rectangle(0, 0, Width - 16, Height); break; } e.Graphics.DrawRectangle(p, boxRect); } if (Checked) { Color fillColor = CheckState == CheckState.Indeterminate ? borderColor : MetroPaint.GetStyleColor(Style); using (SolidBrush b = new SolidBrush(fillColor)) { Rectangle boxCheck = new Rectangle(boxRect.Left + 2, boxRect.Top + 2, 9, 9); e.Graphics.FillRectangle(b, boxCheck); } } TextRenderer.DrawText(e.Graphics, Text, MetroFonts.CheckBox(metroCheckBoxSize, metroCheckBoxWeight), textRect, foreColor, MetroPaint.GetTextFormatFlags(TextAlign)); OnCustomPaintForeground(new MetroPaintEventArgs(Color.Empty, foreColor, e.Graphics)); if (displayFocusRectangle && isFocused) { ControlPaint.DrawFocusRectangle(e.Graphics, ClientRectangle); } }
protected virtual void OnPaintForeground(PaintEventArgs e) { Color borderColor, foreColor; if (useCustomForeColor) { foreColor = ForeColor; if (isHovered && !isPressed && Enabled) { borderColor = MetroPaint.BorderColor.CheckBox.Hover(Theme); } else if (isHovered && isPressed && Enabled) { borderColor = MetroPaint.BorderColor.CheckBox.Press(Theme); } else if (!Enabled) { borderColor = MetroPaint.BorderColor.CheckBox.Disabled(Theme); } else { borderColor = MetroPaint.BorderColor.CheckBox.Normal(Theme); } } else { if (isHovered && !isPressed && Enabled) { foreColor = MetroPaint.ForeColor.CheckBox.Hover(Theme); borderColor = MetroPaint.BorderColor.CheckBox.Hover(Theme); } else if (isHovered && isPressed && Enabled) { foreColor = MetroPaint.ForeColor.CheckBox.Press(Theme); borderColor = MetroPaint.BorderColor.CheckBox.Press(Theme); } else if (!Enabled) { foreColor = MetroPaint.ForeColor.CheckBox.Disabled(Theme); borderColor = MetroPaint.BorderColor.CheckBox.Disabled(Theme); } else { foreColor = !useStyleColors ? MetroPaint.ForeColor.CheckBox.Normal(Theme) : MetroPaint.GetStyleColor(Style); borderColor = MetroPaint.BorderColor.CheckBox.Normal(Theme); } } e.Graphics.SmoothingMode = SmoothingMode.HighQuality; using (var p = new Pen(borderColor)) { var boxRect = new Rectangle(0, Height / 2 - 6, 12, 12); e.Graphics.DrawEllipse(p, boxRect); } if (Checked) { Color fillColor = MetroPaint.GetStyleColor(Style); using (var b = new SolidBrush(fillColor)) { var boxRect = new Rectangle(3, Height / 2 - 3, 6, 6); e.Graphics.FillEllipse(b, boxRect); } } e.Graphics.SmoothingMode = SmoothingMode.Default; var textRect = new Rectangle(16, 0, Width - 16, Height); TextRenderer.DrawText(e.Graphics, Text, MetroFonts.CheckBox(metroCheckBoxSize, metroCheckBoxWeight), textRect, foreColor, MetroPaint.GetTextFormatFlags(TextAlign)); OnCustomPaintForeground(new MetroPaintEventArgs(Color.Empty, foreColor, e.Graphics)); if (displayFocusRectangle && isFocused) { ControlPaint.DrawFocusRectangle(e.Graphics, ClientRectangle); } }
protected virtual void OnPaintForeground(PaintEventArgs e) { Color color; Color foreColor; if (this.useCustomForeColor) { foreColor = this.ForeColor; if (this.isHovered && !this.isPressed && base.Enabled) { color = MetroPaint.BorderColor.CheckBox.Hover(this.Theme); } else if (!this.isHovered || !this.isPressed || !base.Enabled) { color = (base.Enabled ? MetroPaint.BorderColor.CheckBox.Normal(this.Theme) : MetroPaint.BorderColor.CheckBox.Disabled(this.Theme)); } else { color = MetroPaint.BorderColor.CheckBox.Press(this.Theme); } } else if (this.isHovered && !this.isPressed && base.Enabled) { foreColor = MetroPaint.ForeColor.CheckBox.Hover(this.Theme); color = MetroPaint.BorderColor.CheckBox.Hover(this.Theme); } else if (this.isHovered && this.isPressed && base.Enabled) { foreColor = MetroPaint.ForeColor.CheckBox.Press(this.Theme); color = MetroPaint.BorderColor.CheckBox.Press(this.Theme); } else if (base.Enabled) { foreColor = (!this.useStyleColors ? MetroPaint.ForeColor.CheckBox.Normal(this.Theme) : MetroPaint.GetStyleColor(this.Style)); color = MetroPaint.BorderColor.CheckBox.Normal(this.Theme); } else { foreColor = MetroPaint.ForeColor.CheckBox.Disabled(this.Theme); color = MetroPaint.BorderColor.CheckBox.Disabled(this.Theme); } e.Graphics.SmoothingMode = SmoothingMode.HighQuality; using (Pen pen = new Pen(color)) { Rectangle rectangle = new Rectangle(0, base.Height / 2 - 6, 12, 12); e.Graphics.DrawEllipse(pen, rectangle); } if (base.Checked) { using (SolidBrush solidBrush = new SolidBrush(MetroPaint.GetStyleColor(this.Style))) { Rectangle rectangle1 = new Rectangle(3, base.Height / 2 - 3, 6, 6); e.Graphics.FillEllipse(solidBrush, rectangle1); } } e.Graphics.SmoothingMode = SmoothingMode.Default; Rectangle rectangle2 = new Rectangle(16, 0, base.Width - 16, base.Height); TextRenderer.DrawText(e.Graphics, this.Text, MetroFonts.CheckBox(this.metroCheckBoxSize, this.metroCheckBoxWeight), rectangle2, foreColor, MetroPaint.GetTextFormatFlags(this.TextAlign)); this.OnCustomPaintForeground(new MetroPaintEventArgs(Color.Empty, foreColor, e.Graphics)); if (this.displayFocusRectangle && this.isFocused) { ControlPaint.DrawFocusRectangle(e.Graphics, base.ClientRectangle); } }