if u draw a line,
anyidea how to rub it off (delete it)#
thank you very much
Printable View
if u draw a line,
anyidea how to rub it off (delete it)#
thank you very much
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. :)
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
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:
Private clear As Boolean = False Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs) If clear Then Dim MyPen As Pen = New Pen(Color.Red, 3) Dim graphicsObject As Graphics = Me.CreateGraphics graphicsObject.DrawLine(MyPen, 0, 0, Button1.Left + 35, Button1.Top + 12) clear = False End If End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click clear = False Me.Invalidate() End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click clear = True Me.Invalidate() End Sub