Convert from color to brush

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

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

+8
source share
5 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 
+10
source share

A brush is a fill painting style that includes both color and pattern. The pen is similar to a brush, but defines a line drawing style. To switch from color to brush, you need to create a new brush and give it a color. The Brush class itself is abstract; its child classes define various basic, custom drawing patterns. The handles are similar, but as the lines are drawn as if they were filled with rectangles, a brush may be required to adjust the β€œfill” of the line. Then the Pen object has additional properties that determine the style characteristic of drawing a line. Take a look at MSDN: http://msdn.microsoft.com/en-us/library/d78x2d7s%28v=VS.71%29.aspx

+5
source share
 Dim myColor As Color Dim myBrush As Brush Dim myPen As Pen 'From Color to brush/pen myBrush = New SolidBrush(myColor) myPen = New Pen(myColor) 'From Brush to color/pen myPen = New Pen(myBrush) myColor = New Pen(myBrush).Color 'From Pen to color/brush myColor = myPen.Color myBrush = New SolidBrush(myPen.Color) 
+5
source share

These are completely different things.

Here is an article entitled "Pens, Brushes, and Colors," http://msdn.microsoft.com/en-us/library/aa983677(v=vs.71).aspx

Pens
The pen is used to draw lines, curves, and contour shapes.

Brushes
Brushes are objects that are used with the Graphics object to create solid shapes and to render text.

Both pens and brushes have a β€œcolor” that they use ... but you cannot turn the color into a brush. It is like a car. You cannot turn β€œRed” into a car, but the car may be red.

+4
source share

pen is used to draw outlines of a figure.
a brush is used to fill the inner area of ​​a closed drawing.
Color is color.

The brush and pen may have the same color, but their role is different

+1
source share

All Articles