Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between solidcolorbrush and brush

Tags:

c#

.net

wpf

What is the the differnce between solidcolorbrush and brush, In WPF (C#).

SolidColorBrush br = new SolidColorBrush(Colors.Red);

and

Brush br = Brushes.Red;
like image 224
daniyalahmad Avatar asked Dec 16 '22 03:12

daniyalahmad


1 Answers

To answer your question No difference.

Brushes.Red returns SolidColorBrush only. Its definition is like:

public static SolidColorBrush Red { get; }

You can assume its default template which Microsoft provides you for basic colors.


Use SolidColorBrush constructor in case you want to provide your own custom A,R,G,B values for color.

This will get you actual Red color:

enter image description here

SolidColorBrush anotherBrush = 
                     new SolidColorBrush(Color.FromArgb(255, 255, 0, 0));

This will get you Red color with G component set to 100 byte and B component set to 50 byte.

enter image description here

SolidColorBrush anotherBrush = 
                     new SolidColorBrush(Color.FromArgb(255, 255, 100, 50));
like image 88
Rohit Vats Avatar answered Dec 29 '22 01:12

Rohit Vats