示例#1
0
        /// <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 (Graphics 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>
        /// 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>
        /// 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);
            }
        }
示例#4
0
        /// <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>
        /// 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())
            {
                proposedSize         = new Size(int.MaxValue, int.MaxValue);
                preferredSize        = TextRenderer.MeasureText(g, this.Text ?? string.Empty, ModernFonts.CheckBox(this.FontSize, this.FontWeight), proposedSize, ModernPaint.GetTextFormatFlags(this.TextAlign));
                preferredSize.Width += 16;
            }

            return(preferredSize);
        }
        /// <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);
            }
        }
示例#7
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);
            }
        }
示例#8
0
        /// <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);
            }
        }
示例#9
0
        /// <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>
        /// 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);
                }
            }
        }
示例#11
0
        /// <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();
        }
示例#12
0
        /// <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));
            }
        }