4
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?

Vaccano
  • 78,325
  • 149
  • 468
  • 850

4 Answers4

5

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)
Phil Lamb
  • 1,407
  • 10
  • 15
2

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.

Chris Taylor
  • 52,623
  • 10
  • 78
  • 89
1

A Brush does not have a color.

You use a Brush with a Color for filling/painting etc.

Some brushes do have a color (HatchBrush has two), so you will need to cast to the type of brush and compare colors then:

((HatchBrush)backBrush).BackgroundColor == SystemColors.ActiveCaption
Oded
  • 489,969
  • 99
  • 883
  • 1,009
1

Have you tried the SystemBrushes namespace?

if (backBrush == SystemBrushes.ActiveCaption)
{...
Vivek Jain
  • 3,811
  • 6
  • 30
  • 47
Zenzer
  • 6,100
  • 1
  • 16
  • 6