Refresh method

stenhoeve

New member
Joined
Feb 4, 2013
Messages
3
Programming Experience
Beginner
Hi,

I have have the following question. If I have drawn several lines onto a form, label, etc. how can I use the refresh method to delte these lines in reverse order. So if I clicked on a button the last line deletes, another click and another line is deleted?

Thank you,

Sten
 
Store the information about everything to be drawn, and draw them in Paint event. If you want to delete last item just remove that information from your storage and refresh.
 
Store the information about everything to be drawn, and draw them in Paint event. If you want to delete last item just remove that information from your storage and refresh.

Thank you for your answer. I am a total noob, I have written the code below, how do I implement you remark?

VB.NET:
[/SIZE]  
 Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNextCut.Click
        'Prepare GraphicsFun variable for graphics calls
        Dim GraphicsFun As Graphics
        GraphicsFun = Label6.CreateGraphics()
        'Use a red pen color to draw a line and use the provided coordinates
        Dim PenColor As New Pen(Color.Red)
        Dim a As Single = txtStartX.Text
        Dim b As Single = txtStartY.Text
        Dim c As Single = txtEndX.Text
        Dim d As Single = txtEndY.Text
        GraphicsFun.DrawLine(PenColor, a, b, c, d)
    End Sub
    Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        Refresh()
    End Sub
[SIZE=2]
 
"CreateGraphics" - get rid of that.

Your information is a,b,c,d which is the x/y values of two points. For example define a Line Structure that has two Point values. Use a List(Of Line) to keep all lines values, each time you create a new line you add it to the list.
For drawing call the controls Refresh to make the control do its painting, here you handle Paint event where you draw all the lines in the list.
 
Check out this example, which allows the user to draw lines on a PictureBox by clicking and dragging:

Very Simple Drawing Program

As JohnH says, if you want to delete a drawn line then simply remove it from list and then redraw everything.
 
Back
Top