|
-
Oct 29th, 2008, 03:25 PM
#1
Thread Starter
Hyperactive Member
[RESOLVED] Draw Line...then erase
is there a way to draw a line, then erace it it with the graphics.drawline? So if a draw it twice, it just goes back to the original image.
Visual Studio .NET 2005/.NET Framework 2.0
-
Oct 29th, 2008, 03:37 PM
#2
Hyperactive Member
Re: Draw Line...then erase
don't draw it anymore in the OnPaint method... only do it as long as you need it. Once you get rid of it force a redraw of whatever it was that you are drawing on...
-
Oct 29th, 2008, 03:38 PM
#3
Re: Draw Line...then erase
Well, you can keep a copy of the original image, and save your lines in a collection. When you want to draw a line or remove a line, just add or remove the line to/from the collection, then make a copy of the original image and draw all the lines in the collection on it.
Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
- Abraham Lincoln -
-
Oct 29th, 2008, 03:41 PM
#4
Hyperactive Member
Re: Draw Line...then erase
Ahh i think i misunderstood... You want to several lines and then erase maybe one of them? if that's the case i would make a class to keep track of your lines or just keep a List of them. then when you want to erase one remove it from your list. In your OnPaint draw each line in the list...
-
Oct 29th, 2008, 03:59 PM
#5
Hyperactive Member
Re: Draw Line...then erase
Sorry this is exactly what Stanav suggested, i didn't even see it until later sorry for repeating....
Something like this:
class for lines:
vb Code:
' a basic line class ' you can define other properties to make this more sophisticated Public Class MyLine Protected points As List(Of Point) Public Sub New(ByVal point1 As Point, ByVal point2 As Point) points = New List(Of Point) points.Add(point1) points.Add(point2) End Sub ' this method will be called by the object that needs to be drawn upon Public Sub Draw(ByVal g As Graphics) g.DrawLines(Pens.Black, points.ToArray()) End Sub End Class
Your application can keep a list of these line objects then in your Paint method..
vb Code:
Private Sub Panel1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Panel1.Paint 'Me.lines is a reference to your list of lines 'add a MyLine object representing a line each time your app needs to draw one 'iterate over all MyLine objects and tell them to draw themselves For Each line As MyLine In Me.lines line.Draw(e.Graphics) Next End Sub
Last edited by wy125; Oct 29th, 2008 at 04:02 PM.
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
|