/// <summary> /// OnPaintForeground method. /// </summary> /// <param name="e">PaintEventArgs instance.</param> protected virtual void OnPaintForeground(PaintEventArgs e) { if (!this.UseCustomForeColor) { this._baseTextBox.ForeColor = ModernPaint.ForeColor.Button.Normal(this.ThemeStyle); } else { this._baseTextBox.ForeColor = this.ForeColor; } Color borderColor = ModernPaint.BorderColor.Button.Normal(this.ThemeStyle); if (this.UseStyleColors) { borderColor = ModernPaint.GetStyleColor(this.ColorStyle); } using (Pen p = new Pen(borderColor)) { e.Graphics.DrawRectangle(p, new Rectangle(0, 0, Width - 1, Height - 1)); } this.DrawIcon(e.Graphics); }
/// <summary> /// Draws the selected tab bar. /// </summary> /// <param name="index">The index.</param> /// <param name="graphics">The graphics.</param> private void DrawSelectedTabBar(int index, Graphics graphics) { if (this.Alignment == TabAlignment.Left || this.Alignment == TabAlignment.Right) { return; } using (Brush selectionBrush = new SolidBrush(ModernPaint.GetStyleColor(this.ColorStyle))) { int y = 0; if (this.Alignment == TabAlignment.Top) { y = this.GetTabRect(index).Bottom + 2 - TabBottomBorderHeight; } else if (this.Alignment == TabAlignment.Bottom) { y = this.GetTabRect(index).Top - 2; } Rectangle selectedTabRect = this.GetTabRect(index); Rectangle borderRectangle = new Rectangle(selectedTabRect.X + ((index == 0) ? 2 : 0), y, selectedTabRect.Width + ((index == 0) ? 0 : 2), TabBottomBorderHeight); graphics.FillRectangle(selectionBrush, borderRectangle); } }
/// <summary> /// Raises the <see cref="E:PaintBackground" /> event. /// </summary> /// <param name="e">The <see cref="PaintEventArgs"/> instance containing the event data.</param> protected override void OnPaintBackground(PaintEventArgs e) { try { Color backColor = this.BackColor; if (!this.UseCustomBackColor) { backColor = ModernPaint.BackColor.Form(this.ThemeStyle); if (this.Parent is ModernTile) { backColor = ModernPaint.GetStyleColor(this.ColorStyle); } } if (backColor.A == 255 && this.BackgroundImage == null) { e.Graphics.Clear(backColor); return; } base.OnPaintBackground(e); this.OnCustomPaintBackground(new ModernPaintEventArgs(backColor, Color.Empty, e.Graphics)); } catch { this.Invalidate(); } }
/// <summary> /// OnPaint method. /// </summary> /// <param name="e">A <see cref="T:System.Windows.Forms.PaintEventArgs" /> that contains the event data.</param> protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); using (SolidBrush brush = new SolidBrush(ModernPaint.GetStyleColor(this.ColorStyle))) { e.Graphics.SmoothingMode = SmoothingMode.HighSpeed; e.Graphics.FillRectangle(brush, new Rectangle(0, 0, this._progressWidth, this.TopBarHeight)); } }
/// <summary> /// Applies the modern style event. /// </summary> private void ApplyModernStyleEvent() { this.Enter += (s, e) => { this.LineColor = UseStyleColors ? ControlPaint.Light(ModernPaint.GetStyleColor(ColorStyle), 0.2F) : ModernPaint.BackColor.Button.Normal(ThemeStyle); }; this.Leave += (s, e) => { this.LineColor = ModernPaint.BackColor.Button.Disabled(ThemeStyle); }; this.EnabledChanged += (s, e) => { this.LineColor = this.Enabled ? (UseStyleColors ? ControlPaint.Light(ModernPaint.GetStyleColor(ColorStyle), 0.2F) : ModernPaint.BackColor.Button.Normal(ThemeStyle)) : ModernPaint.BackColor.Button.Disabled(ThemeStyle); }; }
protected override void WndProc(ref Message m) { switch (m.Msg) { case WM_SETFOCUS: this.LineColor = this.UseStyleColors ? ControlPaint.Light(ModernPaint.GetStyleColor(this.ColorStyle), 0.2F) : ModernPaint.BackColor.Button.Normal(this.ThemeStyle); break; case WM_NCPAINT: this.LineColor = this.Focused ? (this.UseStyleColors ? ControlPaint.Light(ModernPaint.GetStyleColor(this.ColorStyle), 0.2F) : ModernPaint.BackColor.Button.Normal(this.ThemeStyle)) : ModernPaint.BackColor.Button.Disabled(this.ThemeStyle); break; default: break; } base.WndProc(ref m); }
/// <summary> /// Raises the <see cref="E:System.Windows.Forms.Control.Paint" /> event. /// </summary> /// <param name="e">A <see cref="T:System.Windows.Forms.PaintEventArgs" /> that contains the event data.</param> protected override void OnPaint(PaintEventArgs e) { try { if (this.GetStyle(ControlStyles.AllPaintingInWmPaint)) { this.OnPaintBackground(e); } Color foreColor = this.UseCustomForeColor ? this.ForeColor : ModernPaint.ForeColor.Tile.Normal(this.ThemeStyle); Color borderColor = ModernPaint.GetStyleColor(this.ColorStyle); using (Pen pen = new Pen(borderColor)) { e.Graphics.DrawLines( pen, new[] { new Point(0, 0), new Point(0, this.Height - 1), new Point(this.Width - 1, this.Height - 1), new Point(this.Width - 1, 0), new Point(0, 0) }); } using (SolidBrush brush = ModernPaint.GetStyleBrush(this.ColorStyle)) { e.Graphics.FillRectangle(brush, 0, 0, this.Width, this.HeaderHeight); } Rectangle textRectangle = new Rectangle(0, 0, this.Width, (int)this.HeaderHeight); TextRenderer.DrawText(e.Graphics, this.Text, ModernFonts.CheckBox(this.FontSize, this.FontWeight), textRectangle, foreColor, ModernPaint.GetTextFormatFlags(this.TextAlign)); this.OnCustomPaint(new ModernPaintEventArgs(Color.Empty, Color.Empty, e.Graphics)); this.OnPaintForeground(e); } catch { this.Invalidate(); } }
/// <summary> /// Applies the modern style. /// </summary> private void ApplyModernStyle() { this.BackColor = ModernPaint.BackColor.Form(this.ThemeStyle); this.CommandsBackColor = this.BackColor; this.HelpBackColor = this.BackColor; this.ViewBackColor = this.BackColor; this.ForeColor = ModernPaint.ForeColor.Button.Normal(this.ThemeStyle); this.CategoryForeColor = this.ForeColor; this.CommandsForeColor = this.ForeColor; this.HelpForeColor = this.ForeColor; this.ViewForeColor = this.ForeColor; this.CommandsLinkColor = ModernPaint.ForeColor.Link.Normal(this.ThemeStyle); this.CommandsActiveLinkColor = ModernPaint.ForeColor.Link.Hover(this.ThemeStyle); this.CommandsDisabledLinkColor = ModernPaint.ForeColor.Link.Disabled(this.ThemeStyle); this.LineColor = this.UseStyleColors ? ControlPaint.Light(ModernPaint.GetStyleColor(this.ColorStyle), 0.2F) : ModernPaint.BackColor.Button.Normal(this.ThemeStyle); this.Refresh(); }
/// <summary> /// OnDrawItem method. /// </summary> /// <param name="e">DrawItemEventArgs instance.</param> protected override void OnDrawItem(DrawItemEventArgs e) { if (e.Index >= 0) { Color foreColor; Color backColor = BackColor; if (!this.UseCustomBackColor) { backColor = ModernPaint.BackColor.Form(this.ThemeStyle); } if (e.State == (DrawItemState.NoAccelerator | DrawItemState.NoFocusRect) || e.State == DrawItemState.None) { using (SolidBrush brush = new SolidBrush(backColor)) { e.Graphics.FillRectangle(brush, new Rectangle(e.Bounds.Left, e.Bounds.Top, e.Bounds.Width, e.Bounds.Height)); } foreColor = ModernPaint.ForeColor.Link.Normal(this.ThemeStyle); } else { using (SolidBrush brush = new SolidBrush(ModernPaint.GetStyleColor(this.ColorStyle))) { e.Graphics.FillRectangle(brush, new Rectangle(e.Bounds.Left, e.Bounds.Top, e.Bounds.Width, e.Bounds.Height)); } foreColor = ModernPaint.ForeColor.Tile.Normal(this.ThemeStyle); } Rectangle textRectangle = new Rectangle(0, e.Bounds.Top, e.Bounds.Width, e.Bounds.Height); TextRenderer.DrawText(e.Graphics, this.GetItemText(this.Items[e.Index]), ModernFonts.ComboBox(this.FontSize, this.FontWeight), textRectangle, foreColor, TextFormatFlags.Left | TextFormatFlags.VerticalCenter); } else { base.OnDrawItem(e); } }
/// <summary> /// Apply modern style. /// </summary> private void ApplyModernStyle() { this.BorderStyle = BorderStyle.None; this.CellBorderStyle = DataGridViewCellBorderStyle.None; this.EnableHeadersVisualStyles = false; this.SelectionMode = DataGridViewSelectionMode.FullRowSelect; this.Font = new Font("Segoe UI", 11f, FontStyle.Regular, GraphicsUnit.Pixel); this.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.DisableResizing; this.AllowUserToResizeRows = false; this.AllowUserToResizeColumns = true; this.ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.None; this.RowHeadersBorderStyle = DataGridViewHeaderBorderStyle.None; if (!this.UseCustomBackColor) { this.BackColor = ModernPaint.BackColor.Form(this.ThemeStyle); this.BackgroundColor = ModernPaint.BackColor.Form(this.ThemeStyle); this.GridColor = ModernPaint.BackColor.Form(this.ThemeStyle); this.ColumnHeadersDefaultCellStyle.BackColor = ModernPaint.GetStyleColor(this.ColorStyle); this.RowHeadersDefaultCellStyle.BackColor = ModernPaint.GetStyleColor(this.ColorStyle); this.DefaultCellStyle.BackColor = ModernPaint.BackColor.Form(this.ThemeStyle); this.DefaultCellStyle.SelectionBackColor = ControlPaint.Light(ModernPaint.GetStyleColor(this.ColorStyle), this.HighlightPercentage); this.RowsDefaultCellStyle.BackColor = ModernPaint.BackColor.Form(this.ThemeStyle); this.RowsDefaultCellStyle.SelectionBackColor = ControlPaint.Light(ModernPaint.GetStyleColor(this.ColorStyle), this.HighlightPercentage); this.RowHeadersDefaultCellStyle.SelectionBackColor = ControlPaint.Light(ModernPaint.GetStyleColor(this.ColorStyle), this.HighlightPercentage); this.ColumnHeadersDefaultCellStyle.SelectionBackColor = ControlPaint.Light(ModernPaint.GetStyleColor(this.ColorStyle), this.HighlightPercentage); } if (!this.UseCustomForeColor) { this.ForeColor = ModernPaint.ForeColor.Button.Disabled(this.ThemeStyle); this.ColumnHeadersDefaultCellStyle.ForeColor = ModernPaint.ForeColor.Button.Press(this.ThemeStyle); this.RowHeadersDefaultCellStyle.ForeColor = ModernPaint.ForeColor.Button.Press(this.ThemeStyle); this.DefaultCellStyle.SelectionForeColor = Color.FromArgb(17, 17, 17); this.RowsDefaultCellStyle.SelectionForeColor = Color.FromArgb(17, 17, 17); this.RowHeadersDefaultCellStyle.SelectionForeColor = Color.FromArgb(17, 17, 17); this.ColumnHeadersDefaultCellStyle.SelectionForeColor = Color.FromArgb(17, 17, 17); } }
/// <summary> /// Retrieves the size of a rectangular area into which a control can be fitted. /// </summary> /// <param name="proposedSize">The custom-sized area for a control.</param> /// <returns>An ordered pair of type <see cref="T:System.Drawing.Size" /> representing the width and height of a rectangle.</returns> public override Size GetPreferredSize(Size proposedSize) { Size preferredSize; base.GetPreferredSize(proposedSize); using (Graphics g = this.CreateGraphics()) { proposedSize = new Size(int.MaxValue, int.MaxValue); preferredSize = TextRenderer.MeasureText(g, this.Text ?? string.Empty, ModernFonts.Label(this.FontSize, this.FontWeight), proposedSize, ModernPaint.GetTextFormatFlags(this.TextAlign)); } return(preferredSize); }
/// <summary> /// DrawProgressText method. /// </summary> /// <param name="graphics">Graphics instance.</param> private void DrawProgressText(Graphics graphics) { if (!this.ShowText && !this.ShowPercentText) { return; } Color foreColor = this.Enabled ? ModernPaint.ForeColor.ProgressBar.Normal(this.ThemeStyle) : ModernPaint.ForeColor.ProgressBar.Disabled(this.ThemeStyle); if (this.ShowText) { TextRenderer.DrawText(graphics, this.Text, ModernFonts.ProgressBar(this.FontSize, this.FontWeight), this.ClientRectangle, foreColor, ModernPaint.GetTextFormatFlags(this.TextAlign)); } if (this.ShowPercentText) { TextRenderer.DrawText(graphics, this.ProgressPercentText, ModernFonts.ProgressBar(this.FontSize, this.FontWeight), this.ClientRectangle, foreColor, ModernPaint.GetTextFormatFlags(this.PercentTextAlign)); } }
/// <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); } }
/// <summary> /// DrawProgressContinuous method. /// </summary> /// <param name="graphics">Graphics instance.</param> private void DrawProgressContinuous(Graphics graphics) { graphics.FillRectangle(ModernPaint.GetStyleBrush(this.ColorStyle), 0, 0, (int)this.ProgressBarWidth, this.ClientRectangle.Height); }
/// <summary> /// DrawProgressMarquee method. /// </summary> /// <param name="graphics">Graphics instance.</param> private void DrawProgressMarquee(Graphics graphics) { graphics.FillRectangle(ModernPaint.GetStyleBrush(this.ColorStyle), this._marqueeX, 0, this.ProgressBarMarqueeWidth, this.ClientRectangle.Height); }
/// <summary> /// OnPaintForeground method. /// </summary> /// <param name="e">PaintEventArgs instance.</param> protected virtual void OnPaintForeground(PaintEventArgs e) { Color borderColor; Color foreColor; if (this._isHovered && !this._isPressed && this.Enabled) { foreColor = ModernPaint.ForeColor.CheckBox.Hover(this.ThemeStyle); borderColor = ModernPaint.BorderColor.CheckBox.Hover(this.ThemeStyle); } else if (this._isHovered && this._isPressed && this.Enabled) { foreColor = ModernPaint.ForeColor.CheckBox.Press(this.ThemeStyle); borderColor = ModernPaint.BorderColor.CheckBox.Press(this.ThemeStyle); } else if (!this.Enabled) { foreColor = ModernPaint.ForeColor.CheckBox.Disabled(this.ThemeStyle); borderColor = ModernPaint.BorderColor.CheckBox.Disabled(this.ThemeStyle); } else { foreColor = !this.UseStyleColors ? ModernPaint.ForeColor.CheckBox.Normal(this.ThemeStyle) : ModernPaint.GetStyleColor(this.ColorStyle); borderColor = ModernPaint.BorderColor.CheckBox.Normal(this.ThemeStyle); } using (Pen pen = new Pen(borderColor)) { Rectangle boxRectangle = new Rectangle(this.StatusTextRightToLeft ? 0 : (this.ShowStatusText ? 30 : 0), 0, this.ClientRectangle.Width - (this.ShowStatusText ? 31 : 1), this.ClientRectangle.Height - 1); e.Graphics.DrawRectangle(pen, boxRectangle); } Color fillColor = this.Checked ? ModernPaint.GetStyleColor(this.ColorStyle) : ModernPaint.BorderColor.CheckBox.Normal(this.ThemeStyle); using (SolidBrush brush = new SolidBrush(fillColor)) { Rectangle boxRectangle = new Rectangle(this.StatusTextRightToLeft ? 2 : (this.ShowStatusText ? 32 : 2), 2, this.ClientRectangle.Width - (this.ShowStatusText ? 34 : 4), this.ClientRectangle.Height - 4); e.Graphics.FillRectangle(brush, boxRectangle); } Color backColor = this.BackColor; if (!this.UseCustomBackColor) { backColor = ModernPaint.BackColor.Form(this.ThemeStyle); } using (SolidBrush brush = new SolidBrush(backColor)) { int left = this.Checked ? this.Width - 11 : (this.ShowStatusText ? 30 : 0); Rectangle boxRectangle = new Rectangle(this.StatusTextRightToLeft ? left - 30 : left, 0, 11, this.ClientRectangle.Height); e.Graphics.FillRectangle(brush, boxRectangle); } using (SolidBrush brush = new SolidBrush(ModernPaint.BorderColor.CheckBox.Hover(this.ThemeStyle))) { int left = this.Checked ? this.Width - 10 : (this.ShowStatusText ? 30 : 0); Rectangle boxRectangle = new Rectangle(this.StatusTextRightToLeft ? left - 30 : left, 0, 10, this.ClientRectangle.Height); e.Graphics.FillRectangle(brush, boxRectangle); } if (this.ShowStatusText) { Rectangle textRectangle = new Rectangle(this.StatusTextRightToLeft ? this.ClientRectangle.Width - (this.ShowStatusText ? 31 : 1) : 0, 0, 30, this.ClientRectangle.Height); TextRenderer.DrawText(e.Graphics, this.Text, ModernFonts.Link(this.FontSize, this.FontWeight), textRectangle, foreColor, ModernPaint.GetTextFormatFlags(this.TextAlign)); } if (this.DisplayFocus && this._isFocused) { ControlPaint.DrawFocusRectangle(e.Graphics, this.ClientRectangle); } }
/// <summary> /// Raises the <see cref="E:PaintForeground" /> event. /// </summary> /// <param name="e">The <see cref="PaintEventArgs"/> instance containing the event data.</param> protected virtual void OnPaintForeground(PaintEventArgs e) { Color foreColor; if (this.UseCustomBackground) { foreColor = ModernPaint.GetStyleColor(this.ColorStyle); } else { if (this.Parent is ModernTile) { foreColor = ModernPaint.ForeColor.Tile.Normal(this.ThemeStyle); } else { foreColor = ModernPaint.GetStyleColor(this.ColorStyle); } } using (Pen forePen = new Pen(foreColor, (float)this.Width / 5)) { int padding = (int)Math.Ceiling((float)this.Width / 10); e.Graphics.SmoothingMode = SmoothingMode.HighQuality; if (this.Value != -1) { float sweepAngle; float progFrac = (float)(this.Value - this.Minimum) / (float)(this.Maximum - this.Minimum); if (this.EnsureVisible) { sweepAngle = 30 + (300f * progFrac); } else { sweepAngle = 360f * progFrac; } if (this.Backwards) { sweepAngle = -sweepAngle; } e.Graphics.DrawArc(forePen, padding, padding, this.Width - (2 * padding) - 1, this.Height - (2 * padding) - 1, this._angle, sweepAngle); } else { int maxOffset = 180; for (int offset = 0; offset <= maxOffset; offset += 15) { int alpha = 290 - (offset * 290 / maxOffset); if (alpha > 255) { alpha = 255; } if (alpha < 0) { alpha = 0; } Color color = Color.FromArgb(alpha, forePen.Color); using (Pen gradPen = new Pen(color, forePen.Width)) { float startAngle = this._angle + ((offset - (this.EnsureVisible ? 30 : 0)) * (this.Backwards ? 1 : -1)); float sweepAngle = 15 * (this.Backwards ? 1 : -1); e.Graphics.DrawArc(gradPen, padding, padding, this.Width - (2 * padding) - 1, this.Height - (2 * padding) - 1, startAngle, sweepAngle); } } } } this.OnCustomPaintForeground(new ModernPaintEventArgs(Color.Empty, foreColor, e.Graphics)); }
/// <summary> /// OnPaintForeground method. /// </summary> /// <param name="e">PaintEventArgs instance.</param> protected virtual void OnPaintForeground(PaintEventArgs e) { Color borderColor; Color foreColor; if (this._isHovered && !this._isPressed && this.Enabled) { borderColor = ModernPaint.BorderColor.Button.Hover(this.ThemeStyle); foreColor = ModernPaint.ForeColor.Button.Hover(this.ThemeStyle); } else if (this._isHovered && this._isPressed && this.Enabled) { borderColor = ModernPaint.BorderColor.Button.Press(this.ThemeStyle); foreColor = ModernPaint.ForeColor.Button.Press(this.ThemeStyle); } else if (!this.Enabled) { borderColor = ModernPaint.BorderColor.Button.Disabled(this.ThemeStyle); foreColor = ModernPaint.ForeColor.Button.Disabled(this.ThemeStyle); } else { borderColor = ModernPaint.BorderColor.Button.Normal(this.ThemeStyle); if (this.UseCustomForeColor) { foreColor = this.ForeColor; } else if (this.UseStyleColors) { foreColor = ModernPaint.GetStyleColor(this.ColorStyle); } else { foreColor = ModernPaint.ForeColor.Button.Normal(this.ThemeStyle); } } using (Pen pen = new Pen(borderColor)) { Rectangle borderRect = new Rectangle(0, 0, this.Width - 1, this.Height - 1); e.Graphics.DrawRectangle(pen, borderRect); } if (this.Highlight && !this._isHovered && !this._isPressed && this.Enabled) { using (Pen pen = ModernPaint.GetStylePen(this.ColorStyle)) { Rectangle borderRectangle = new Rectangle(0, 0, this.Width - 1, this.Height - 1); e.Graphics.DrawRectangle(pen, borderRectangle); borderRectangle = new Rectangle(1, 1, this.Width - 3, this.Height - 3); e.Graphics.DrawRectangle(pen, borderRectangle); } } TextRenderer.DrawText(e.Graphics, this.Text, ModernFonts.Button(this.FontSize, this.FontWeight), this.ClientRectangle, foreColor, ModernPaint.GetTextFormatFlags(this.TextAlign)); this.OnCustomPaintForeground(new ModernPaintEventArgs(Color.Empty, foreColor, e.Graphics)); if (this.DisplayFocus && this._isFocused) { ControlPaint.DrawFocusRectangle(e.Graphics, this.ClientRectangle); } }
/// <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 = this.CreateGraphics()) { proposedSize = new Size(int.MaxValue, int.MaxValue); preferredSize = TextRenderer.MeasureText(g, this.ProgressPercentText, ModernFonts.ProgressBar(this.FontSize, this.FontWeight), proposedSize, ModernPaint.GetTextFormatFlags(this.PercentTextAlign)); } return(preferredSize); }
/// <summary> /// Updates the base text box. /// </summary> private void UpdateBaseTextBox() { if (!this._baseTextBox.Visible) { return; } this.SuspendLayout(); this._baseTextBox.SuspendLayout(); if (this.UseCustomBackColor) { this._baseTextBox.BackColor = this.BackColor; } else { this._baseTextBox.BackColor = ModernPaint.BackColor.Form(this.ThemeStyle); } if (!this.Enabled) { if (this.Parent != null) { if (this.Parent is ModernTile) { this._baseTextBox.ForeColor = ModernPaint.ForeColor.Tile.Disabled(this.ThemeStyle); } else { if (this.UseStyleColors) { this._baseTextBox.ForeColor = ModernPaint.GetStyleColor(this.ColorStyle); } else { this._baseTextBox.ForeColor = ModernPaint.ForeColor.Label.Disabled(this.ThemeStyle); } } } else { if (this.UseStyleColors) { this._baseTextBox.ForeColor = ModernPaint.GetStyleColor(this.ColorStyle); } else { this._baseTextBox.ForeColor = ModernPaint.ForeColor.Label.Disabled(this.ThemeStyle); } } } else { if (this.Parent != null) { if (this.Parent is ModernTile) { this._baseTextBox.ForeColor = ModernPaint.ForeColor.Tile.Normal(this.ThemeStyle); } else { if (this.UseStyleColors) { this._baseTextBox.ForeColor = ModernPaint.GetStyleColor(this.ColorStyle); } else { this._baseTextBox.ForeColor = ModernPaint.ForeColor.Label.Normal(this.ThemeStyle); } } } else { if (this.UseStyleColors) { this._baseTextBox.ForeColor = ModernPaint.GetStyleColor(this.ColorStyle); } else { this._baseTextBox.ForeColor = ModernPaint.ForeColor.Label.Normal(this.ThemeStyle); } } } this._baseTextBox.Font = ModernFonts.Label(this.FontSize, this.FontWeight); this._baseTextBox.Text = this.Text; this._baseTextBox.BorderStyle = BorderStyle.None; this.Size = this.GetPreferredSize(Size.Empty); this._baseTextBox.ResumeLayout(); this.ResumeLayout(); }
/// <summary> /// Configures the control. /// </summary> /// <param name="control">The control.</param> private void ConfigControl(Control control) { control.BackColor = ModernPaint.BackColor.Form(ThemeStyle); control.ForeColor = ModernPaint.ForeColor.Button.Normal(ThemeStyle); if (control is Button) { Button button = (Button)control; button.Enter += (s, e) => { button.FlatAppearance.BorderSize = 0; }; button.GotFocus += (s, e) => { button.BackColor = ModernPaint.BackColor.Button.Press(ThemeStyle); button.ForeColor = ModernPaint.ForeColor.Button.Press(ThemeStyle); }; button.Leave += (s, e) => { button.FlatAppearance.BorderSize = 1; }; button.LostFocus += (s, e) => { button.BackColor = ModernPaint.BackColor.Button.Normal(ThemeStyle); button.ForeColor = ModernPaint.ForeColor.Button.Normal(ThemeStyle); }; button.EnabledChanged += (s, e) => { button.BackColor = button.Enabled ? ModernPaint.BackColor.Button.Normal(ThemeStyle) : ModernPaint.BackColor.Button.Disabled(ThemeStyle); button.ForeColor = button.Enabled ? ModernPaint.ForeColor.Button.Normal(ThemeStyle) : ModernPaint.ForeColor.Button.Disabled(ThemeStyle); }; button.Font = ModernFonts.Button(ModernFontSize.Small, ModernFontWeight.Bold); button.BackColor = button.Enabled ? ModernPaint.BackColor.Button.Normal(ThemeStyle) : ModernPaint.BackColor.Button.Disabled(ThemeStyle); button.ForeColor = button.Enabled ? ModernPaint.ForeColor.Button.Normal(ThemeStyle) : ModernPaint.ForeColor.Button.Disabled(ThemeStyle); button.FlatStyle = FlatStyle.Flat; button.FlatAppearance.BorderSize = button.Focused ? 0 : 1; button.FlatAppearance.BorderColor = ModernPaint.BorderColor.Button.Normal(ThemeStyle); button.FlatAppearance.MouseOverBackColor = ModernPaint.BackColor.Button.Hover(ThemeStyle); button.FlatAppearance.MouseDownBackColor = ModernPaint.BackColor.Button.Press(ThemeStyle); button.FlatAppearance.CheckedBackColor = ModernPaint.BorderColor.Button.Press(ThemeStyle); button.Height = 25; if (string.IsNullOrEmpty(button.Text) || string.IsNullOrEmpty(button.Text.Trim())) { button.Width = 25; } } if (control is ListBox) { ListBox listBox = (ListBox)control; listBox.BorderStyle = BorderStyle.FixedSingle; listBox.DrawItem += (s, e) => { if (listBox.Items.Count > 0) { Color backColor = listBox.BackColor; Color foreColor = listBox.ForeColor; bool isSelected = (e.State & DrawItemState.Selected) != 0; bool isHovered = (e.State & DrawItemState.HotLight) != 0; if (isHovered) { backColor = ModernPaint.BackColor.Button.Hover(ThemeStyle); foreColor = ModernPaint.ForeColor.Button.Hover(ThemeStyle); } else { if (isSelected) { backColor = listBox.Focused ? ControlPaint.Light(ModernPaint.GetStyleColor(ColorStyle), 0.2F) : ModernPaint.BackColor.Button.Disabled(ThemeStyle); foreColor = listBox.Focused ? Color.FromArgb(17, 17, 17) : ModernPaint.ForeColor.Button.Normal(ThemeStyle); } else { backColor = ModernPaint.BackColor.Form(ThemeStyle); foreColor = ModernPaint.ForeColor.Button.Normal(ThemeStyle); } } e.DrawBackground(); using (SolidBrush brush = new SolidBrush(backColor)) { e.Graphics.FillRectangle(brush, e.Bounds); } using (SolidBrush brush = new SolidBrush(foreColor)) { e.Graphics.DrawString(listBox.Items[e.Index].ToString(), e.Font, brush, listBox.GetItemRectangle(e.Index).Location); } e.DrawFocusRectangle(); } }; } if (control is PropertyGrid) { PropertyGrid propertyGrid = (PropertyGrid)control; propertyGrid.CommandsBackColor = propertyGrid.BackColor; propertyGrid.HelpBackColor = propertyGrid.BackColor; propertyGrid.ViewBackColor = propertyGrid.BackColor; propertyGrid.ForeColor = propertyGrid.ForeColor; propertyGrid.CategoryForeColor = propertyGrid.ForeColor; propertyGrid.CommandsForeColor = propertyGrid.ForeColor; propertyGrid.HelpForeColor = propertyGrid.ForeColor; propertyGrid.ViewForeColor = propertyGrid.ForeColor; propertyGrid.CommandsLinkColor = ModernPaint.ForeColor.Link.Normal(ThemeStyle); propertyGrid.CommandsActiveLinkColor = ModernPaint.ForeColor.Link.Hover(ThemeStyle); propertyGrid.CommandsDisabledLinkColor = ModernPaint.ForeColor.Link.Disabled(ThemeStyle); propertyGrid.LineColor = UseStyleColors ? ControlPaint.Light(ModernPaint.GetStyleColor(ColorStyle), 0.2F) : ModernPaint.BackColor.Button.Normal(ThemeStyle); propertyGrid.HelpVisible = true; propertyGrid.PropertySort = PropertySort.NoSort; propertyGrid.ExpandAllGridItems(); propertyGrid.Enter += (s, e) => { propertyGrid.LineColor = UseStyleColors ? ControlPaint.Light(ModernPaint.GetStyleColor(ColorStyle), 0.2F) : ModernPaint.BackColor.Button.Normal(ThemeStyle); }; propertyGrid.Leave += (s, e) => { propertyGrid.LineColor = ModernPaint.BackColor.Button.Disabled(ThemeStyle); }; } if (control.Controls.Count > 0) { foreach (Control item in control.Controls) { this.ConfigControl(item); } } }
/// <summary> /// OnPaintForeground method. /// </summary> /// <param name="e">PaintEventArgs instance.</param> protected virtual void OnPaintForeground(PaintEventArgs e) { Color foreColor; if (this.UseCustomForeColor) { foreColor = this.ForeColor; } else { if (this._isHovered && !this._isPressed && this.Enabled) { foreColor = ModernPaint.ForeColor.Link.Hover(this.ThemeStyle); } else if (this._isHovered && this._isPressed && this.Enabled) { foreColor = ModernPaint.ForeColor.Link.Press(this.ThemeStyle); } else if (!this.Enabled) { foreColor = ModernPaint.ForeColor.Link.Disabled(this.ThemeStyle); } else { foreColor = !this.UseStyleColors ? ModernPaint.ForeColor.Link.Normal(this.ThemeStyle) : ModernPaint.GetStyleColor(this.ColorStyle); } } TextRenderer.DrawText(e.Graphics, this.Text, ModernFonts.Link(this.FontSize, this.FontWeight), this.ClientRectangle, foreColor, ModernPaint.GetTextFormatFlags(this.TextAlign)); this.OnCustomPaintForeground(new ModernPaintEventArgs(Color.Empty, foreColor, e.Graphics)); if (this.DisplayFocus && this._isFocused) { ControlPaint.DrawFocusRectangle(e.Graphics, this.ClientRectangle); } }
/// <summary> /// OnPaint method. /// </summary> /// <param name="e">A <see cref="T:System.Windows.Forms.PaintEventArgs" /> that contains the event data.</param> protected override void OnPaint(PaintEventArgs e) { Color backColor = this.UseCustomBackColor ? this.BackColor : ModernPaint.BackColor.Form(this.ThemeStyle); Color foreColor = this.UseCustomForeColor ? this.ForeColor : ModernPaint.ForeColor.Title(this.ThemeStyle); e.Graphics.Clear(backColor); if (this.ShowHeader) { Rectangle bounds = new Rectangle(20, 20, this.ClientRectangle.Width - (2 * 20), 40); TextFormatFlags flags = TextFormatFlags.EndEllipsis | this.GetTextFormatFlags(); TextRenderer.DrawText(e.Graphics, this.Text, ModernFonts.GetDefaultFont(this.FontSize, this.FontWeight), bounds, foreColor, flags); } if (this.BackImage != null && this.BackImageMaxSize != 0) { Image image = ModernImage.ResizeImage(this.BackImage, new Rectangle(0, 0, this.BackImageMaxSize, this.BackImageMaxSize)); if (this.BackImageInvert) { image = ModernImage.ResizeImage(this.ThemeStyle == ModernThemeStyle.Dark ? this._invertBackImage : this.BackImage, new Rectangle(0, 0, this.BackImageMaxSize, this.BackImageMaxSize)); } switch (this.BackImageAlign) { case ModernFormBackImageAlign.TopLeft: e.Graphics.DrawImage(image, 0 + this.BackImagePadding.Left, 0 + this.BackImagePadding.Top); break; case ModernFormBackImageAlign.TopRight: e.Graphics.DrawImage(image, ClientRectangle.Right - (this.BackImagePadding.Right + image.Width), 0 + this.BackImagePadding.Top); break; case ModernFormBackImageAlign.BottomLeft: e.Graphics.DrawImage(image, 0 + this.BackImagePadding.Left, ClientRectangle.Bottom - (image.Height + this.BackImagePadding.Bottom)); break; case ModernFormBackImageAlign.BottomRight: e.Graphics.DrawImage(image, ClientRectangle.Right - (this.BackImagePadding.Right + image.Width), ClientRectangle.Bottom - (image.Height + this.BackImagePadding.Bottom)); break; } } if (this.ShowStatusStrip) { using (SolidBrush brush = ModernPaint.GetStyleBrush(this.ColorStyle)) { this.StatusStrip.Height = 20; this.StatusStrip.Width = this.Width - 20; this.StatusStrip.Location = new Point(0, this.Height - 20); Rectangle bottomRectangle = new Rectangle(0, this.Height - 20, this.Width, 20); e.Graphics.FillRectangle(brush, bottomRectangle); } } if (this.Resizable && (this.SizeGripStyle == SizeGripStyle.Auto || this.SizeGripStyle == SizeGripStyle.Show)) { using (SolidBrush brush = new SolidBrush(ModernPaint.ForeColor.Button.Disabled(this.ThemeStyle))) { Size resizeHandleSize = new Size(2, 2); e.Graphics.FillRectangles( brush, new Rectangle[] { new Rectangle(new Point(this.ClientRectangle.Width - 6, this.ClientRectangle.Height - 6), resizeHandleSize), new Rectangle(new Point(this.ClientRectangle.Width - 10, this.ClientRectangle.Height - 10), resizeHandleSize), new Rectangle(new Point(this.ClientRectangle.Width - 10, this.ClientRectangle.Height - 6), resizeHandleSize), new Rectangle(new Point(this.ClientRectangle.Width - 6, this.ClientRectangle.Height - 10), resizeHandleSize), new Rectangle(new Point(this.ClientRectangle.Width - 14, this.ClientRectangle.Height - 6), resizeHandleSize), new Rectangle(new Point(this.ClientRectangle.Width - 6, this.ClientRectangle.Height - 14), resizeHandleSize) }); } } if (this.ShowBorder && this.WindowState != FormWindowState.Maximized) { Color borderColor = ModernPaint.GetStyleColor(this.ColorStyle); using (Pen pen = new Pen(borderColor)) { e.Graphics.DrawLines( pen, new[] { new Point(0, 0), new Point(0, this.Height), new Point(this.Width - 1, this.Height), new Point(this.Width - 1, 0), new Point(0, 0) }); } } }
/// <summary> /// OnPaintForeground method. /// </summary> /// <param name="e">PaintEventArgs instance.</param> protected virtual void OnPaintForeground(PaintEventArgs e) { Color foreColor; if (this._isHovered && !this._isPressed && this.Enabled) { foreColor = ModernPaint.ForeColor.Tile.Hover(this.ThemeStyle); } else if (this._isHovered && this._isPressed && this.Enabled) { foreColor = ModernPaint.ForeColor.Tile.Press(this.ThemeStyle); } else if (!this.Enabled) { foreColor = ModernPaint.ForeColor.Tile.Disabled(this.ThemeStyle); } else { foreColor = ModernPaint.ForeColor.Tile.Normal(this.ThemeStyle); } if (this.UseCustomForeColor) { foreColor = this.ForeColor; } e.Graphics.SmoothingMode = SmoothingMode.HighQuality; e.Graphics.CompositingQuality = CompositingQuality.HighQuality; if (this.UseTileImage) { if (this.TileImage != null) { Rectangle imageRectangle; switch (this.TileImageAlign) { case ContentAlignment.BottomLeft: imageRectangle = new Rectangle(new Point(0, this.Height - this.TileImage.Height), new Size(this.TileImage.Width, this.TileImage.Height)); break; case ContentAlignment.BottomCenter: imageRectangle = new Rectangle(new Point((this.Width / 2) - (this.TileImage.Width / 2), this.Height - this.TileImage.Height), new Size(this.TileImage.Width, this.TileImage.Height)); break; case ContentAlignment.BottomRight: imageRectangle = new Rectangle(new Point(this.Width - this.TileImage.Width, this.Height - this.TileImage.Height), new Size(this.TileImage.Width, this.TileImage.Height)); break; case ContentAlignment.MiddleLeft: imageRectangle = new Rectangle(new Point(0, (this.Height / 2) - (this.TileImage.Height / 2)), new Size(this.TileImage.Width, this.TileImage.Height)); break; case ContentAlignment.MiddleCenter: imageRectangle = new Rectangle(new Point((this.Width / 2) - (this.TileImage.Width / 2), (this.Height / 2) - (this.TileImage.Height / 2)), new Size(this.TileImage.Width, this.TileImage.Height)); break; case ContentAlignment.MiddleRight: imageRectangle = new Rectangle(new Point(this.Width - this.TileImage.Width, (this.Height / 2) - (this.TileImage.Height / 2)), new Size(this.TileImage.Width, this.TileImage.Height)); break; case ContentAlignment.TopLeft: imageRectangle = new Rectangle(new Point(0, 0), new Size(this.TileImage.Width, this.TileImage.Height)); break; case ContentAlignment.TopCenter: imageRectangle = new Rectangle(new Point((this.Width / 2) - (this.TileImage.Width / 2), 0), new Size(this.TileImage.Width, this.TileImage.Height)); break; case ContentAlignment.TopRight: imageRectangle = new Rectangle(new Point(this.Width - this.TileImage.Width, 0), new Size(this.TileImage.Width, this.TileImage.Height)); break; default: imageRectangle = new Rectangle(new Point(0, 0), new Size(this.TileImage.Width, this.TileImage.Height)); break; } e.Graphics.DrawImage(this.TileImage, imageRectangle); } } if (this.ShowTileCount) { Size countSize = TextRenderer.MeasureText(this.TileCount.ToString(), ModernFonts.Tile(this.TileCountFontSize, this.TileCountFontWeight)); e.Graphics.TextRenderingHint = TextRenderingHint.AntiAlias; TextRenderer.DrawText(e.Graphics, this.TileCount.ToString(), ModernFonts.Tile(this.TileCountFontSize, this.TileCountFontWeight), new Point(this.Width - countSize.Width, 0), foreColor); e.Graphics.TextRenderingHint = TextRenderingHint.SystemDefault; } TextFormatFlags flags = ModernPaint.GetTextFormatFlags(this.TextAlign) | TextFormatFlags.LeftAndRightPadding | TextFormatFlags.EndEllipsis; Rectangle textRectangle = this.ClientRectangle; if (this._isPressed) { textRectangle.Inflate(-2, -2); } TextRenderer.DrawText(e.Graphics, this.Text, ModernFonts.Tile(this.FontSize, this.FontWeight), textRectangle, foreColor, flags); if (this._isFocused) { ControlPaint.DrawFocusRectangle(e.Graphics, this.ClientRectangle); } }
/// <summary> /// Applies the modern style. /// </summary> private void ApplyModernStyle() { this.BackColor = ModernPaint.BackColor.Form(this.ThemeStyle); this.ForeColor = ModernPaint.ForeColor.Button.Normal(this.ThemeStyle); this.LineColor = this.UseStyleColors ? ModernPaint.GetStyleColor(this.ColorStyle) : this.ForeColor; }
/// <summary> /// Raises the <see cref="E:System.Windows.Forms.TreeView.DrawNode" /> event. /// </summary> /// <param name="e">A <see cref="T:System.Windows.Forms.DrawTreeNodeEventArgs" /> that contains the event data.</param> protected override void OnDrawNode(DrawTreeNodeEventArgs e) { if (this.Nodes.Count > 0) { Color backColor = this.BackColor; Color foreColor = this.ForeColor; bool isSelected = (e.State & TreeNodeStates.Selected) != 0; bool isHovered = (e.State & TreeNodeStates.Hot) != 0; if (isHovered) { backColor = ModernPaint.BackColor.Button.Hover(this.ThemeStyle); foreColor = ModernPaint.ForeColor.Button.Hover(this.ThemeStyle); } else { if (isSelected) { backColor = (this.Focused || !this.Enabled) ? ControlPaint.Light(ModernPaint.GetStyleColor(this.ColorStyle), 0.2F) : ModernPaint.BackColor.Button.Disabled(this.ThemeStyle); foreColor = (this.Focused || !this.Enabled) ? Color.FromArgb(17, 17, 17) : ModernPaint.ForeColor.Button.Normal(this.ThemeStyle); } else { backColor = ModernPaint.BackColor.Form(this.ThemeStyle); foreColor = ModernPaint.ForeColor.Button.Normal(this.ThemeStyle); } } Rectangle rectangle; if (this.ShowLines) { rectangle = new Rectangle(e.Bounds.X, e.Bounds.Y, this.Width - e.Bounds.X, e.Bounds.Height); } else { rectangle = new Rectangle(0, e.Bounds.Y, this.Width, e.Bounds.Height); } using (SolidBrush brush = new SolidBrush(backColor)) { e.Graphics.FillRectangle(brush, rectangle); } using (SolidBrush brush = new SolidBrush(foreColor)) { e.Graphics.DrawString(e.Node.Text, this.Font, brush, e.Bounds); } } base.OnDrawNode(e); }
/// <summary> /// Raises the <see cref="E:PaintForeground" /> event. /// </summary> /// <param name="e">The <see cref="PaintEventArgs"/> instance containing the event data.</param> protected virtual void OnPaintForeground(PaintEventArgs e) { Color foreColor; if (this.UseCustomForeColor) { foreColor = this.ForeColor; } else { if (!this.Enabled) { if (this.Parent != null) { if (this.Parent is ModernTile) { foreColor = ModernPaint.ForeColor.Tile.Disabled(this.ThemeStyle); } else { foreColor = ModernPaint.ForeColor.Label.Normal(this.ThemeStyle); } } else { foreColor = ModernPaint.ForeColor.Label.Disabled(this.ThemeStyle); } } else { if (this.Parent != null) { if (this.Parent is ModernTile) { foreColor = ModernPaint.ForeColor.Tile.Normal(this.ThemeStyle); } else { if (this.UseStyleColors) { foreColor = ModernPaint.GetStyleColor(this.ColorStyle); } else { foreColor = ModernPaint.ForeColor.Label.Normal(this.ThemeStyle); } } } else { if (this.UseStyleColors) { foreColor = ModernPaint.GetStyleColor(this.ColorStyle); } else { foreColor = ModernPaint.ForeColor.Label.Normal(this.ThemeStyle); } } } } if (this.CanSelectText) { this.CreateBaseTextBox(); this.UpdateBaseTextBox(); if (!this._baseTextBox.Visible) { TextRenderer.DrawText(e.Graphics, this.Text, ModernFonts.Label(this.FontSize, this.FontWeight), this.ClientRectangle, foreColor, ModernPaint.GetTextFormatFlags(this.TextAlign)); } } else { this.DestroyBaseTextbox(); TextRenderer.DrawText(e.Graphics, this.Text, ModernFonts.Label(this.FontSize, this.FontWeight), this.ClientRectangle, foreColor, ModernPaint.GetTextFormatFlags(this.TextAlign, this.WordWrap)); this.OnCustomPaintForeground(new ModernPaintEventArgs(Color.Empty, foreColor, e.Graphics)); } }
/// <summary> /// Draws the tab. /// </summary> /// <param name="index">The index.</param> /// <param name="graphics">The graphics.</param> private void DrawTab(int index, Graphics graphics) { Color foreColor; Color backColor = this.BackColor; if (!this.UseCustomBackColor) { backColor = ModernPaint.BackColor.Form(this.ThemeStyle); } TabPage tabPage = this.TabPages[index]; Rectangle tabRectangle = this.GetTabRect(index); if (!this.Enabled) { foreColor = ModernPaint.ForeColor.Label.Disabled(this.ThemeStyle); } else { if (this.UseCustomForeColor) { foreColor = Control.DefaultForeColor; } else { foreColor = !this.UseStyleColors ? ModernPaint.ForeColor.TabControl.Normal(this.ThemeStyle) : ModernPaint.GetStyleColor(this.ColorStyle); } } if (index == 0) { tabRectangle.X = this.DisplayRectangle.X; } Rectangle bgRectangle = tabRectangle; tabRectangle.Width += 20; using (Brush bgBrush = new SolidBrush(backColor)) { graphics.FillRectangle(bgBrush, bgRectangle); } TextRenderer.DrawText(graphics, tabPage.Text, ModernFonts.TabControl(this.FontSize, this.FontWeight), tabRectangle, foreColor, backColor, ModernPaint.GetTextFormatFlags(ContentAlignment.MiddleLeft)); }
/// <summary> /// OnPaintForeground method. /// </summary> /// <param name="e">PaintEventArgs instance.</param> protected virtual void OnPaintForeground(PaintEventArgs e) { Color borderColor; Color foreColor; if (this.UseCustomForeColor) { foreColor = this.ForeColor; if (this._isHovered && !this._isPressed && this.Enabled) { borderColor = ModernPaint.BorderColor.CheckBox.Hover(this.ThemeStyle); } else if (this._isHovered && this._isPressed && this.Enabled) { borderColor = ModernPaint.BorderColor.CheckBox.Press(this.ThemeStyle); } else if (!this.Enabled) { borderColor = ModernPaint.BorderColor.CheckBox.Disabled(this.ThemeStyle); } else { borderColor = ModernPaint.BorderColor.CheckBox.Normal(this.ThemeStyle); } } else { if (this._isHovered && !this._isPressed && this.Enabled) { foreColor = ModernPaint.ForeColor.CheckBox.Hover(this.ThemeStyle); borderColor = ModernPaint.BorderColor.CheckBox.Hover(this.ThemeStyle); } else if (this._isHovered && this._isPressed && this.Enabled) { foreColor = ModernPaint.ForeColor.CheckBox.Press(this.ThemeStyle); borderColor = ModernPaint.BorderColor.CheckBox.Press(this.ThemeStyle); } else if (!this.Enabled) { foreColor = ModernPaint.ForeColor.CheckBox.Disabled(this.ThemeStyle); borderColor = ModernPaint.BorderColor.CheckBox.Disabled(this.ThemeStyle); } else { foreColor = !this.UseStyleColors ? ModernPaint.ForeColor.CheckBox.Normal(this.ThemeStyle) : ModernPaint.GetStyleColor(this.ColorStyle); borderColor = ModernPaint.BorderColor.CheckBox.Normal(this.ThemeStyle); } } e.Graphics.SmoothingMode = SmoothingMode.HighQuality; using (Pen pen = new Pen(borderColor)) { Rectangle boxRectangle = new Rectangle(0, (this.Height / 2) - 6, 12, 12); e.Graphics.DrawEllipse(pen, boxRectangle); } if (this.Checked) { Color fillColor = ModernPaint.GetStyleColor(this.ColorStyle); using (SolidBrush brush = new SolidBrush(fillColor)) { Rectangle boxRectangle = new Rectangle(3, (this.Height / 2) - 3, 6, 6); e.Graphics.FillEllipse(brush, boxRectangle); } } e.Graphics.SmoothingMode = SmoothingMode.Default; Rectangle textRectangle = new Rectangle(16, 0, this.Width - 16, this.Height); TextRenderer.DrawText(e.Graphics, this.Text, ModernFonts.CheckBox(this.FontSize, this.FontWeight), textRectangle, foreColor, ModernPaint.GetTextFormatFlags(this.TextAlign)); this.OnCustomPaintForeground(new ModernPaintEventArgs(Color.Empty, foreColor, e.Graphics)); if (this.DisplayFocus && this._isFocused) { ControlPaint.DrawFocusRectangle(e.Graphics, this.ClientRectangle); } }
/// <summary> /// Measures the text. /// </summary> /// <param name="text">The text.</param> /// <returns>Preferred size.</returns> private Size MeasureText(string text) { Size preferredSize; using (Graphics g = CreateGraphics()) { Size proposedSize = new Size(int.MaxValue, int.MaxValue); preferredSize = TextRenderer.MeasureText(g, text ?? string.Empty, ModernFonts.TabControl(this.FontSize, this.FontWeight), proposedSize, ModernPaint.GetTextFormatFlags(ContentAlignment.MiddleLeft) | TextFormatFlags.NoPadding); } return(preferredSize); }