Results 1 to 5 of 5

Thread: [RESOLVED] Draw Line...then erase

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2006
    Posts
    413

    Resolved [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

  2. #2
    Hyperactive Member
    Join Date
    Mar 2002
    Location
    Boston, MA
    Posts
    391

    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...

  3. #3
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    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 -

  4. #4
    Hyperactive Member
    Join Date
    Mar 2002
    Location
    Boston, MA
    Posts
    391

    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...

  5. #5
    Hyperactive Member
    Join Date
    Mar 2002
    Location
    Boston, MA
    Posts
    391

    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:
    1. ' a basic line class
    2. ' you can define other properties to make this more sophisticated
    3. Public Class MyLine
    4.     Protected points As List(Of Point)
    5.  
    6.  
    7.  
    8.     Public Sub New(ByVal point1 As Point, ByVal point2 As Point)
    9.         points = New List(Of Point)
    10.         points.Add(point1)
    11.         points.Add(point2)
    12.     End Sub
    13.  
    14.  
    15.     ' this method will be called by the object that needs to be drawn upon
    16.     Public Sub Draw(ByVal g As Graphics)
    17.         g.DrawLines(Pens.Black, points.ToArray())
    18.     End Sub
    19.  
    20.  
    21.  
    22.  
    23.  
    24. End Class

    Your application can keep a list of these line objects then in your Paint method..
    vb Code:
    1. Private Sub Panel1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Panel1.Paint
    2.  
    3.         'Me.lines is a reference to your list of lines
    4.         'add a MyLine object representing a line each time your app needs to draw one
    5.        
    6.         'iterate over all MyLine objects and tell them to draw themselves
    7.         For Each line As MyLine In Me.lines
    8.             line.Draw(e.Graphics)
    9.         Next
    10.  
    11.  
    12.  
    13.     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
  •  



Click Here to Expand Forum to Full Width