2

When you set a SimpleButton.Appearance.BackColor property to a DX Skin color (@Danger, @Question, @Success, @Primary or @Info as shown in the image):

Color selector

The SimpleButton.Appearance.ForeColor property is evaluated at run-time with the appropriate color (if the skin color is too dark, Color.White would be used; if the skin color is too bright, Color.Black would be used):

Dark @Success:

Dark

Light @Success:

Light

How do I get this ForeColor that is evaluated in run-time?

I have tried getting SimpleButton.ForeColor, SimpleButton.Appearance.ForeColor and SimpleButton.Appearance.GetForeColor(e.GraphicsCache) (I'm trying to get this color inside a CustomDraw event) but it's always Color.Black

2 Answers2

2

I ended up with this extension method according to this implementation of the W3C standard, making some modifications per Miral's tests:

public static Color GetContrastColor(this Color color)
{
    return (color.R * 0.299M) + (color.G * 0.587M) + (color.B * 0.114M) > 149 ? 
        Color.Black : 
        Color.White;
}
0

The DevExpress.LookAndFeel.DXSkinColors.ForeColors.Information property should offer the ForeColor for the Information/Success coloring.

Brendon
  • 1,238
  • 1
  • 7
  • 8
  • You're correct--this is getting the back color. My mistake, sorry. – Brendon Nov 07 '19 at 19:00
  • This is also giving me the green-ish color (same as `BackColor`)! – Ivan García Topete Nov 07 '19 at 22:08
  • Are you using SVG skins/palettes or the Bitmap GDI skin? In my test, the fore color IS a green-ish color, just a lighter shade than the actual button. – Brendon Nov 07 '19 at 22:11
  • I'm using The Beziere skin with the Leaf Rustle pallet that has the `SimpleButton` `ForeColor` set to `Color.White` (as in the question), but the end-user can change pallets. So if the user selects, say, the High Contrast White pallet, then the `SimpleButton` `ForeColor` changes to `Color.Black`. I want to get the black or white color depending on the skin – Ivan García Topete Nov 07 '19 at 22:17