Page 1 of 1

What is wrong with this code

Posted: Wed Jan 02, 2013 10:49 pm
by XTechVB
i have this simple graphics path but i cant fill it with a color
Code: Select all
    Private Function DrawLeftTriangle(ByVal r As Rectangle) As GraphicsPath
        Dim path As New GraphicsPath
        path.AddLine(r.X, r.Y + Convert.ToInt32(r.Height / 2), r.X + r.Width, r.Y)
        path.AddLine(r.X, r.Y + Convert.ToInt32(r.Height / 2), r.X + r.Width, r.Y + r.Height)
        path.AddLine(r.X + r.Width, r.Y, r.X + r.Width, r.Y + r.Height)
        path.CloseFigure()
        Return path
    End Function
and i use it with this code
Code: Select all
        e.Graphics.FillPath(Brushes.Red, DrawLeftTriangle(New Rectangle(50, 50, 10, 10)))
        e.Graphics.DrawPath(Pens.Black, DrawLeftTriangle(New Rectangle(50, 50, 10, 10)))
this only draws the outline border but it doesn fill the interior Why?

Re: What is wrong with this code

Posted: Wed Jan 02, 2013 11:25 pm
by clanc789
You might have to Draw it first and then Fill it? Dont know, I suck with graphics.

Re: What is wrong with this code

Posted: Thu Jan 03, 2013 2:48 am
by smashapps
You're only changing the colours of the lines of the Rectangle.

To fill it you can use:
Code: Select all
Dim redbrush As New SolidBrush(Color.Red)
e.Graphics.FillRectangle(redbrush, x, y, width, height)

Re: What is wrong with this code

Posted: Thu Jan 03, 2013 3:52 pm
by XTechVB
smashapps wrote:
You're only changing the colours of the lines of the Rectangle.

To fill it you can use:
Code: Select all
Dim redbrush As New SolidBrush(Color.Red)
e.Graphics.FillRectangle(redbrush, x, y, width, height)
i need to fill a graphics path not a rectangle

Re: What is wrong with this code

Posted: Thu Jan 03, 2013 11:25 pm
by M1z23R
Code: Select all
 Private Function DrawLeftTriangle (ByVal r As Rectangle) As GraphicsPath
Dim path As New GraphicsPath
path. AddLine(r.Right, r.Top, r.Left , r.height/2)
path.addline( r.Left , r.height/2, r.right,r.bottom)
path. AddLine(r.right,r.bottom, r.right,r.top)
path. CloseFigure()
Return path
End Function 


Re: What is wrong with this code

Posted: Fri Jan 04, 2013 12:11 am
by XTechVB
M1z23R wrote:
Code: Select all
 Private Function DrawLeftTriangle (ByVal r As Rectangle) As GraphicsPath
Dim path As New GraphicsPath
path. AddLine(r.Right, r.Top, r.Left , r.height/2)
path.addline( r.Left , r.height/2, r.right,r.bottom)
path. AddLine(r.right,r.bottom, r.right,r.top)
path. CloseFigure()
Return path
End Function 

Doesn't Work