Search code examples
c#.netwinformscolorsbrush

How convert Drawing.Color to Drawing.Brush, Windows Forms


How to Convert from 'System.Drawing.Color' to 'System.Drawing.Brush' ?

This cast does not work.

(Brush)colorDialog1.Color;

I have a color dialog, and I need to pick the color from it and use as Brush color


Solution

  • You have to choose a specific type of Brush, most common is SolidBrush:

    using (Brush brush = new SolidBrush(colorDialog1.Color))
    {
        // perform operations
    }
    

    See http://msdn.microsoft.com/en-us/library/aa983677(v=vs.71).aspx for a list of available brushes.