c# - What is the proper way to create a brush from a color? -


What is the correct way to make brushes from color? I have tried brush b = new brush (color); But this is not allowed. I can use existing colors, but there is no way to make a specific brush in it. I'm using myself to fill a rectangle with solid color.

I have to create the current code and then take it brush , but it does not look right:

  brush b = New pen (color) Brush;  

What should I do about doing this right?

Two current answers include two potential possibilities; If you are using GDI + then you want the new SolidBrush (color) and if you are using WPF, then you want to new SolidColorBrush (color) .

The reason is that brushes is an abstract class, which covers a range of possible brushes that can tile bitmap or apply a gradient Or otherwise can paint with others other than just one color.


Comments