37

I'm developing a WinForm Printing application for our company.

When the document is printed, I need to take the System.Drawing.Color property of each Control on the document and create a System.Drawing.Brush object to draw it.

Is there a way to convert the System.Drawing.Color value to a System.Drawing.Brush value?

NOTE: I've tried looking into the System.Windows.Media.SolidColorBrush() method, but it does not seem to be helpful.

2 Answers2

61

Use the SolidBrush class:

using (SolidBrush brush = new SolidBrush(yourColor)) {
    // ...
}
Frédéric Hamidi
  • 258,201
  • 41
  • 486
  • 479
  • 2
    Jeez! You know how many completely irrelevant posts I looked at that sent me off on wild goose chases? The answer was *so close* but my case was never actually addressed in any of them. –  Apr 20 '11 at 18:23
4

Why not the GDI+ brush?

http://msdn.microsoft.com/en-us/library/system.drawing.solidbrush.solidbrush.aspx

The other one is for WPF.

Daniel A. White
  • 187,200
  • 47
  • 362
  • 445