It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming Visual Basic Forum

Drawing lines that don't disappear

Moderator: dafunkymunky

Drawing lines that don't disappear

Postby crash_continental on Thu Nov 23, 2006 4:59 am

Hi there,

I'm very new to Visual Basic 5 and writing a project where I need to draw lines in one part of my form. I can do this, but the problem is that the lines do not redraw themselves when the form is repainted. I have read many pages of information about this where you override the onpaint argument, but honestly none of this makes sense to me at all. Is there an easy way to make the code below draw lines that stay around? (p.s. I've used the form1 events resize etc., but it take far too long to draw when I do so). Thanks in advance to anyone who can help me.

- daniel

Code: Select all
Public Sub DrawRoutes()

        Dim myPen As New System.Drawing.Pen(System.Drawing.Color.HotPink)
        Dim formGraphics As System.Drawing.Graphics
        formGraphics = Me.CreateGraphics()


        For x As Integer = 1 To 40

            For y As Integer = 1 To 40
                If Waypoints(x, y).valid = True Then
                    'horizontal routes
                    If Waypoints(x + 1, y).valid = True Then
                        formGraphics.DrawLine(myPen, Waypoints(x, y).xposition + 2, Waypoints(x, y).yposition + 2, Waypoints(x, y).xposition + 20, Waypoints(x, y).yposition + 2)
                    End If
                    ' vertical routes
                    If Waypoints(x, y + 1).valid = True Then
                        formGraphics.DrawLine(myPen, Waypoints(x, y).xposition + 2, Waypoints(x, y).yposition + 2, Waypoints(x, y).xposition + 2, Waypoints(x, y).yposition + 20)
                    End If
                    ' routes down and to the right
                    If Waypoints(x + 1, y + 1).valid = True Then
                        formGraphics.DrawLine(myPen, Waypoints(x, y).xposition + 2, Waypoints(x, y).yposition + 2, Waypoints(x, y).xposition + 20, Waypoints(x, y).yposition + 20)
                    End If
                    'routes down and to the left
                    If x > 1 Then
                        If Waypoints(x - 1, y + 1).valid = True Then
                            formGraphics.DrawLine(myPen, Waypoints(x, y).xposition + 2, Waypoints(x, y).yposition + 2, Waypoints(x, y).xposition - 20, Waypoints(x, y).yposition + 20)
                        End If
                    End If

                End If
            Next y
        Next x


        myPen.Dispose()
        formGraphics.Dispose()
        routescreated = True
    End Sub
crash_continental
 
Posts: 0
Joined: Thu Nov 23, 2006 4:47 am

Who is online

Users browsing this forum: No registered users and 7 guests