Filling A Heart Shape
-
Hey guys! I have drawn a Heart, now I want to know how do we fill it with a color once drawn ¿ The reason I'm asking this, is because adding a GraphicsPath and Filling that path, didn't seem to work. I even declared a new Points array, and tried FillPolygon, but that didn't work either. This is what I've done with the Graphicspath
Private startPoint As System.Drawing.Point
Private endPoint As System.Drawing.Point
Private Sub Panel1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Panel1.MouseDown
startPoint.X = e.X
startPoint.Y = e.Y
End Sub
Private Sub Panel1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Panel1.MouseUp
endPoint.X = e.X
endPoint.Y = e.Y
Panel1.Invalidate()
End Sub
Private Sub Panel1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Panel1.Paint
Dim hPath As New System.Drawing.Drawing2D.GraphicsPathDim width As Integer = Math.Max(endPoint.X, startPoint.X) - Math.Min(endPoint.X, startPoint.X) Dim height As Integer = Math.Max(endPoint.Y, startPoint.Y) - Math.Min(endPoint.Y, startPoint.Y) Dim avg As Integer = CInt((width + height) / 2) If avg > 0 Then Dim topLeftCorner As Point = startPoint If endPoint.X < startPoint.X Then topLeftCorner.X = endPoint.X End If If endPoint.Y < startPoint.Y Then topLeftCorner.Y = endPoint.Y End If Dim radius As Integer = CInt(avg / 2) Dim topLeftSquare As New Rectangle(topLeftCorner.X, topLeftCorner.Y, radius, radius) Dim topRightSquare As New Rectangle(topLeftCorner.X + radius, topLeftCorner.Y, radius, radius) e.Graphics.DrawArc(Pens.Black, topLeftSquare, 180.0F, 180.0F) hPath.AddArc(topLeftSquare, 180.0F, 180.0F) e.Graphics.DrawArc(Pens.Black, topRightSquare, 180.0F, 180.0F) hPath.AddArc(topRightSquare, 180.0F, 180.0F) e.Graphics.DrawLine(Pens.Black, topLeftCorner.X, (topLeftCorner.Y + radius) - CInt((radius / 2)), topLeftCorner.X + radius, topLeftCorner.Y + avg) hPath.AddLine(topLeftCorner.X, (topLeftCorner.Y + radius) - CInt((radius / 2)), topLeftCorner.X + radius, topLeftCorner.Y + avg) e.Graphics.DrawLine(Pens.Black, topLeftCorner.X + avg, (topLeftCorner.Y + radius) - CInt((r