Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Combobox Colors conflict #39

Open
DBenS opened this issue May 27, 2017 · 0 comments
Open

Combobox Colors conflict #39

DBenS opened this issue May 27, 2017 · 0 comments

Comments

@DBenS
Copy link

DBenS commented May 27, 2017

Hi Denis,

Today working on an application I saw something that can be usefull to your library.

If we select the DARK THEME and using a BRIGHT COLOR (like BRIGHT YELLOW), the comboboxes show an ugly and unreadable text: white on yellow, in my specific case...

So, I did a little change into COMBOBOX.CS, trying to make it adapt itself to these situations:

protected override void OnDrawItem(DrawItemEventArgs e)
    {
          if (e.Index >= 0)
               {
                Color foreColor = MetroPaint.ForeColor.Link.Normal(Theme);
                Color backColor = BackColor;

                if (!useCustomBackColor)
                {
                    backColor = MetroPaint.BackColor.Form(Theme);
                }

                if ((e.State & DrawItemState.Selected) == DrawItemState.Selected)
                {
                    using (SolidBrush b = new SolidBrush(MetroPaint.GetStyleColor(Style)))
                    {
                        e.Graphics.FillRectangle(b, new Rectangle(e.Bounds.Left, e.Bounds.Top, e.Bounds.Width, e.Bounds.Height));
                    }

                    foreColor = MetroPaint.ForeColor.Tile.Normal(Theme);


                   // -------------------------------------------
                   Color FontForeColor = MetroPaint.GetStyleColor(Style);

                    if (FontForeColor.GetBrightness() >= 0.5)
                    {

                        if (FontForeColor == MetroColors.DarkBlue)
                        {
                            FontForeColor = Color.FromArgb(255, 215, 215, 215);

                        }
                        else
                        {
                            FontForeColor = Color.FromArgb(255, 0, 0, 0);
                        }
                    }
                    else
                    {
                        FontForeColor = Color.FromArgb(255, 255, 255, 255);
                    }

                    foreColor = FontForeColor;
                }

                   // -------------------------------------------


                else
                {
                    using (SolidBrush b = new SolidBrush(backColor))
                    {
                        e.Graphics.FillRectangle(b, new Rectangle(e.Bounds.Left, e.Bounds.Top, e.Bounds.Width, e.Bounds.Height));
                    }
                }

                if (this.DropDownStyle != ComboBoxStyle.DropDown)
                {
                    Rectangle textRect = new Rectangle(0, e.Bounds.Top, e.Bounds.Width, e.Bounds.Height);
                    TextRenderer.DrawText(e.Graphics, GetItemText(Items[e.Index]), MetroFonts.ComboBox(metroComboBoxSize, metroComboBoxWeight), textRect, foreColor, TextFormatFlags.Left | TextFormatFlags.VerticalCenter);
                }
                else
                {
                    Rectangle textRect = new Rectangle(0, e.Bounds.Top, this.textBox.Width, e.Bounds.Height);
                    TextRenderer.DrawText(e.Graphics, GetItemText(Items[e.Index]), MetroFonts.ComboBox(metroComboBoxSize, metroComboBoxWeight), textRect, foreColor, TextFormatFlags.Left | TextFormatFlags.VerticalCenter);
                }
            }
            else
            {
                base.OnDrawItem(e);
            }
        }

This way I can get the combo's self-adapting to any user color scheme.
I guess it can be usefull to other.

Best regards.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant