Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Filling A Heart Shape

Filling A Heart Shape

Scheduled Pinned Locked Moved Visual Basic
graphicsdata-structures
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    hannesHTG
    wrote on last edited by
    #1

    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.GraphicsPath

        Dim 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
    
    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups