Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting from a color to a brush

Tags:

vb.net

How do I convert from system.drawing.color to system.drawing.brushes in vb.net?

Meta question: What is/why the difference between a brush/color/pen?

like image 929
Connor Albright Avatar asked Mar 03 '11 16:03

Connor Albright


2 Answers

This should do it for you:

'just a solid brush:
Using br = New SolidBrush(Colors.Black)
     e.Graphics.FillRectangle(br, New Rectangle(50, 50, 10, 10))
End Using

'A red -> orange gradient, at 45 degrees:
Using br = New LinearGradientBrush(new Rectangle(50, 50, 10, 10), Color.Red, Color.Orange, 25)
     e.Graphics.FillRectangle(br, New Rectangle(50, 50, 10, 10))
End Using
like image 62
Pondidum Avatar answered Oct 29 '22 15:10

Pondidum


A "Brush" is a style of fill drawing, incorporating both a Color and a Pattern. A Pen is similar to a Brush but defines a style of line drawing. To go from a Color to a Brush, you need to create a new Brush and give it the Color. The Brush class itself is abstract; its child classes specify various basic, customizable patterns of drawing. Pens are similar, but as lines are drawn as if they were filled rectangles, a Brush may be necessary to customize the "fill" of the line. The Pen object then has additional properties governing style that are specific to drawing a line. Take a look on MSDN: http://msdn.microsoft.com/en-us/library/d78x2d7s%28v=VS.71%29.aspx

like image 27
KeithS Avatar answered Oct 29 '22 17:10

KeithS