What is wrong with this code

If you need help with a project or need to know how to do something specific in VB.NET then please ask your questions in here.
Forum rules
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
6 posts Page 1 of 1
Contributors
User avatar
XTechVB
VIP - Site Partner
VIP - Site Partner
Posts: 727
Joined: Thu May 20, 2010 10:32 am

What is wrong with this code
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?
You can find me on Facebook or on Skype mihai_92b
User avatar
clanc789
Coding Guru
Coding Guru
Posts: 786
Joined: Tue Nov 02, 2010 4:45 pm

Re: What is wrong with this code
clanc789
You might have to Draw it first and then Fill it? Dont know, I suck with graphics.
Practice makes perfect!

VIP since: 6-10-2011
User avatar
smashapps
Coding Guru
Coding Guru
Posts: 961
Joined: Tue Apr 05, 2011 8:41 am

Re: What is wrong with this code
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)
My name is Tom | Visit my blog where I post new content every day! Tom's Daily Blog | MineCraft is awesome!
User avatar
XTechVB
VIP - Site Partner
VIP - Site Partner
Posts: 727
Joined: Thu May 20, 2010 10:32 am

Re: What is wrong with this code
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
You can find me on Facebook or on Skype mihai_92b
User avatar
M1z23R
VIP - Donator
VIP - Donator
Posts: 622
Joined: Tue Sep 28, 2010 4:55 pm

Re: What is wrong with this code
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 

User avatar
XTechVB
VIP - Site Partner
VIP - Site Partner
Posts: 727
Joined: Thu May 20, 2010 10:32 am

Re: What is wrong with this code
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
You can find me on Facebook or on Skype mihai_92b
6 posts Page 1 of 1
Return to “Coding Help & Support”