Results 1 to 9 of 9

Thread: How to create ' temporary' graphics with text changed event?

Threaded View

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2011
    Posts
    5

    How to create ' temporary' graphics with text changed event?

    Hi,
    I'm in an upper level industrial engineering class in which we're learning some entry level VB programming. We're working on building a program to solve the travelling salesmen problem (finding the shortest path through a collection of cities while visiting each only once) and I'm trying to add some 'fancy' to it so I can learn some more skills.
    The basic program is designed to load a bitmap file of a map into a picture box and a text file with the xy coordinates of any city positions. From there, the user can plot the cities with red squares, draw a random tour through the cities, or tour the cities by always visiting the nearest neighbor not yet visited.
    The modification I'm working on is a method of pointing out a specific city with a black square by entering the city's number (determined from the coordinate file) into a text box.

    Code:
      Private Sub TxtFindCity_textchanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TxtFindCity.TextChanged
            Dim ObjFindCity As Graphics = picShowMap.CreateGraphics
            Dim City As Integer
            If Integer.TryParse(TxtFindCity.Text, City) Then
                If City > myCount - 1 Then
                    City = 0
                    ObjFindCity.FillRectangle(Brushes.Black, myData(City, 0) - 3, myData(City, 1) - 3, 10, 10)
                ElseIf 0 <= City <= myCount - 1 Then
                    ObjFindCity.FillRectangle(Brushes.Black, myData(City, 0) - 3, myData(City, 1) - 3, 10, 10)
                End If
            End If
        End Sub

    So far, the program works, but I want the black squares (but none of the other graphics) that are created to go away once the text box is cleared. As of now they just hang around on the screen until I refresh the entire image with a 'clear map' sub. Any suggestions on how to accomplish this?

    Thanks,
    Andrew
    Attached Images Attached Images  

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width