Results 1 to 4 of 4

Thread: draw a line

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2004
    Location
    UK
    Posts
    43

    draw a line

    if u draw a line,

    anyidea how to rub it off (delete it)#


    thank you very much

  2. #2
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682
    Depends what you are drawing on, if you are drawing on an image then you have to keep a copy of whatever was underneath.

    If you are drawing onto a blank "canvas" so to speak then just use

    picturebox1.CreateGraphics().Clear()

    to revert the whole area to the default colour.

    As soon as you draw the line, it becomes part of the image you drew it onto, it isn't a free floating object that can just be deleted easily.
    I don't live here any more.

  3. #3

    Thread Starter
    Member
    Join Date
    Jan 2004
    Location
    UK
    Posts
    43
    this is the code i used to draw a line over the main form

    Dim MyPen As Pen = New Pen(Color.Red, 3)
    Dim graphicsObject As Graphics = Me.CreateGraphics



    graphicsObject.DrawLine(MyPen, Button1.Left + 23, Button1.Top + 12, Button1.Left + 35, Button1.Top + 12)


    how I would be able to delete that,

    thank you very much, have a nice day

  4. #4
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    That's easy . Put 2 buttons :
    1-Button1 = this clears the form .
    2-Button2 = this draws on the form .

    and paste this code . If you face any problem , post here .
    This basically checks for the variable "clear" , and the trick is in "Me.Invalidate()" function which calls to redraw the form again in case it's invalid .

    VB Code:
    1. Private clear As Boolean = False
    2.  
    3.     Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
    4.         If clear Then
    5.             Dim MyPen As Pen = New Pen(Color.Red, 3)
    6.             Dim graphicsObject As Graphics = Me.CreateGraphics
    7.             graphicsObject.DrawLine(MyPen, 0, 0, Button1.Left + 35, Button1.Top + 12)
    8.             clear = False        
    9.         End If
    10.     End Sub
    11.  
    12.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click        
    13.         clear = False
    14.         Me.Invalidate()
    15.     End Sub
    16.  
    17.     Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    18.         clear = True
    19.         Me.Invalidate()
    20.     End Sub

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