Problem with For Loop

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • RolltheBall
    New Member
    • Jul 2007
    • 15

    #1

    Problem with For Loop

    Hi there.

    I am trying to make a certain symbol to appear upon every mouseclick. However, the symbol is a cross and an arrow head. This is how I tried to do it.


    Code:
    Private Sub Form1_Paint(ByVal sender As Object, ByVal e As _
         System.Windows.Forms.PaintEventArgs) Handles _
         MyBase.Paint
    
    Dim bluePen As New Pen(Color.Blue, 1.5)
            Dim G As Graphics = e.Graphics
    
            For Each p As Point In mypts
                G.DrawLine(bluePen, (p.X - 5), (p.Y - 5), (p.X + 5), (p.X + 5))
                G.DrawLine(bluePen, (p.X + 5), (p.Y - 5), (p.Y - 5), (p.Y + 5))
                Dim end_path As New Drawing2D.GraphicsPath
                end_path.AddLine(0, 0, -4, -4)
                end_path.AddLine(0, 0, 4, -4)
                Dim end_cap As New Drawing2D.CustomLineCap(Nothing, end_path)
                bluePen.CustomEndCap = end_cap
                G.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias
                G.DrawLine(bluePen, (p.X - 4), p.Y, (p.X - 12), (p.Y + 7))
                end_path.Dispose()
                end_cap.Dispose()
            Next
        End Sub
    
        Private Sub Form1_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseClick
            Me.mypts.Add(New Point(e.X, e.Y))
            Me.Invalidate()
        End Sub
    However, the problem is, even the lines now suppose to have the arrow heads are having the end cap after the second click onwards. Advice please.

    Thanks.
Working...