|
-
May 12th, 2010, 02:06 PM
#1
Thread Starter
Hyperactive Member
[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.
-
May 12th, 2010, 02:30 PM
#2
Re: Drawn paths won't go away.
invalidate l1 before drawing the next path
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
May 12th, 2010, 02:37 PM
#3
Thread Starter
Hyperactive Member
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.
-
May 12th, 2010, 02:45 PM
#4
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
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
May 12th, 2010, 02:46 PM
#5
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
 
-
May 12th, 2010, 02:54 PM
#6
Re: Drawn paths won't go away.
try changing this line:
vb Code:
Dim map As New Bitmap(l1.Size.Width, l1.Size.Height, l1.CreateGraphics)
to this:
vb Code:
Dim map As New Bitmap(l1.Size.Width, l1.Size.Height)
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
May 12th, 2010, 02:59 PM
#7
Thread Starter
Hyperactive Member
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.
-
May 12th, 2010, 03:01 PM
#8
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.
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
May 12th, 2010, 03:04 PM
#9
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
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|