Compare brush and color

if (backBrush == SystemColors.ActiveCaption)

It fails. Says you cannot compare brush and color.

How to find brush color?

+3
source share
4 answers

If the backBrush is a SolidColorBrush (based on what you are trying to do, this probably is), you can use:

if(((SolidColorBrush)backBrush).Color == SystemColors.ActiveCaption)
+5
source

If the brush is a SolidBrush, you can compare the brush's Color element. Something like that.

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

Above for WinForms, for WPF you would use SolidColorBrush , not SolidBrush.

+2
source

A Brush .

Brush Color / ..

(HatchBrush ), :

((HatchBrush)backBrush).BackgroundColor == SystemColors.ActiveCaption
+1

SystemBrushes?

if (backBrush == SystemBrushes.ActiveCaption)
{...
+1

Source: https://habr.com/ru/post/1746891/


All Articles