Пример #1
0
        /// <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>
        /// 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);
                }
            }
        }