Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

compare a brush and color

Tags:

c#

colors

brush

if (backBrush == SystemColors.ActiveCaption)

This fails. Says you can't compare a brush and a color.

How do I find the color of the brush?

like image 538
Vaccano Avatar asked Jan 22 '23 00:01

Vaccano


2 Answers

If backBrush is a SolidColorBrush (based on what you're trying to do it probably is) you can use:

if(((SolidColorBrush)backBrush).Color == SystemColors.ActiveCaption)
like image 170
Phil Lamb Avatar answered Jan 27 '23 12:01

Phil Lamb


If the brush is a SolidBrush you can compare the Color member of the brush. Something like this.

SolidBrush solidBrush = brush as SolidBrush;
if (solidBrush != null && solidBrush.Color == SystemColors.ActiveCaption)
{
  // ....
}

The above is for WinForms, for WPF you would use SolidColorBrush rather than SolidBrush.

like image 35
Chris Taylor Avatar answered Jan 27 '23 13:01

Chris Taylor