Brush color VB2008 Pro

  • Thread starter Thread starter Galen Somerville
  • Start date Start date
G

Galen Somerville

Drawing a line with WPF using Line class.

The Line.Stroke is a Brush.

I have many colors but they are all using Color and are argb (or just rbg).

How in the h--- do you get a Color into a Brush.???

Even if I had a Brushes color, how do you get it into a Brush.

I'm betting myself that you don't and the color of the Line is set up before
making the Line call via some obtuse method.

The documentation takes you into about 57 different directions but never
answers the question.

Help

Galen
 
Hello Galen,

I wrote a little example that shows how you convert a color into a
brush. Put a button with the name Button1 on a form and insert the
following code into the form.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles Button1.Click

Dim Clr As Color = Color.FromArgb(255, 255, 0, 0) 'Get color from ARGB

Dim Pn As New Pen(Clr) 'Create pen from color

Dim Br As Brush = Pn.Brush 'Create brush from pen

Dim Gr As Graphics = Button1.CreateGraphics 'Get graphics of button

Dim rect As New Rectangle(0, 0, Button1.Width, Button1.Height) 'Prepare
' rectangle for drawing

Gr.DrawRectangle(Pn, rect) 'Draw rectangle with pen color.
Gr.FillRectangle(Brushes.Brown, rect) 'Fill rectangle with brush.

Gr.Dispose()

End Sub

Best regards,

Martin
 
Hello Galen,

I wrote a little example that shows how you convert a color into a
brush. Put a button with the name Button1 on a form and insert the
following code into the form.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles Button1.Click

Dim Clr As Color = Color.FromArgb(255, 255, 0, 0) 'Get color from ARGB

Dim Pn As New Pen(Clr) 'Create pen from color

Dim Br As Brush = Pn.Brush 'Create brush from pen

Dim Gr As Graphics = Button1.CreateGraphics 'Get graphics of button

Dim rect As New Rectangle(0, 0, Button1.Width, Button1.Height) 'Prepare
' rectangle for drawing

Gr.DrawRectangle(Pn, rect) 'Draw rectangle with pen color.
Gr.FillRectangle(Br, rect) 'Fill rectangle with brush.

Gr.Dispose()

End Sub

Best regards,

Martin
 
Drawing a line with WPF using Line class.

The Line.Stroke is a Brush.

I have many colors but they are all using Color and are argb (or just rbg)..

How in the h--- do you get a Color into a Brush.???

Even if I had a Brushes color, how do you get it into a Brush.

I'm betting myself that you don't and the color of the Line is set up before
making the Line call via some obtuse method.

The documentation takes you into about 57 different directions but never
answers the question.

Help

Galen

In WPF....

Brush is a base class. You need to create a specific kind of
brush... It looks like you are after a SolidColorBrush:

Dim l As New Line()
l.Stroke = New SolidColorBrush(Color.FromRgb(255, 0, 0))

HTH
 
Drawing a line with WPF using Line class.

The Line.Stroke is a Brush.

I have many colors but they are all using Color and are argb (or just
rbg).

How in the h--- do you get a Color into a Brush.???

Even if I had a Brushes color, how do you get it into a Brush.

I'm betting myself that you don't and the color of the Line is set up
before
making the Line call via some obtuse method.

The documentation takes you into about 57 different directions but never
answers the question.

Help

Galen

In WPF....

Brush is a base class. You need to create a specific kind of
brush... It looks like you are after a SolidColorBrush:

Dim l As New Line()
l.Stroke = New SolidColorBrush(Color.FromRgb(255, 0, 0))

HTH

--
Tom Shelton

Thanks Tom and Martin. I'll give those a go.

Galen
 
Back
Top