Results 1 to 9 of 9

Thread: [RESOLVED] Drawn paths won't go away.

  1. #1

    Thread Starter
    Hyperactive Member Troy Lundin's Avatar
    Join Date
    May 2006
    Posts
    489

    Resolved [RESOLVED] Drawn paths won't go away.

    I have this code for drawing a path.

    Code:
            Dim map As New Bitmap(l1.Size.Width, l1.Size.Height, l1.CreateGraphics)
            Dim nextPoint As Point
    
            Using g As Drawing.Graphics = Graphics.FromImage(map)
                Dim dPath As New Drawing2D.GraphicsPath
                For i As Integer = 0 To path.Count - 1
    
                    Try
                        nextPoint = path(i + 1)
                    Catch
                    End Try
    
                    dPath.AddLine(path(i).X * 12 + xMod, _
                                  path(i).Y * 13 + yMod, _
                                  nextPoint.X * 12 + xMod, _
                                  nextPoint.Y * 13 + yMod)
                Next
                l1.CreateGraphics.DrawPath(Drawing.Pens.Black, dPath)
            End Using
    l1 is a Label. When I call this it draws the path fine, but when I call it again it draws another path but doesn't get rid of the first path.

    Basically, I only want one path on the Label at a time.
    Prefix has no suffix, but suffix has a prefix.

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: Drawn paths won't go away.

    invalidate l1 before drawing the next path

  3. #3

    Thread Starter
    Hyperactive Member Troy Lundin's Avatar
    Join Date
    May 2006
    Posts
    489

    Re: Drawn paths won't go away.

    I have already tried invalidating.
    I tried place l1.Invalidate() at the start and end of the method.
    I even tried placing it in the calling method.

    Using l1.Invalidate() causes the paths to not be drawn at all.
    Prefix has no suffix, but suffix has a prefix.

  4. #4
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: Drawn paths won't go away.

    l1.Invalidate() at the start and not at the end of the method should have the right effect

  5. #5
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,109

    Re: Drawn paths won't go away.

    I know nothing about those objects, but I see the AddLine method of dPath being called. That suggests that dPath contains a collection of lines to which you are adding. If that is the case, then there should be a means to clear that collection or else the lines will just be redrawn.
    My usual boring signature: Nothing

  6. #6
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: Drawn paths won't go away.

    try changing this line:

    vb Code:
    1. Dim map As New Bitmap(l1.Size.Width, l1.Size.Height, l1.CreateGraphics)

    to this:

    vb Code:
    1. Dim map As New Bitmap(l1.Size.Width, l1.Size.Height)

  7. #7

    Thread Starter
    Hyperactive Member Troy Lundin's Avatar
    Join Date
    May 2006
    Posts
    489

    Re: Drawn paths won't go away.

    I figured it out. I just put all the code into the Paint event of the label. When I want to draw a line I call l1.Refesh()

    @ Shaggy Hiker
    dPath does contain multiple lines. The points are stored in path.
    Each time I call the method I am creating dPath, so it is empty when I start.

    @ .paul.
    I did try your second suggestion to no avail.

    If there is a way to do this without using the Paint event, I would love to know it. Until then, I am marking this as resolved. Thanks.
    Prefix has no suffix, but suffix has a prefix.

  8. #8
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: [RESOLVED] Drawn paths won't go away.

    in fact, after looking at it again, there is lots of redundant code in your first post.

    first you create a bitmap, that you don't use, then a graphics object that you don't use.
    i really couldn't suggest what you should try next unless you post the full code, including the values for path() + the values of xMod + yMod, so i can debug it for you.

  9. #9
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: [RESOLVED] Drawn paths won't go away.

    the problem with drawing on controls is that your drawing is erased next time the control is painted, which is why you should draw in the Paint event

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