Ik heb een simpel stukje code waarmee ik een lijn/ vierkantje / of een cirkel op een formulier kan tekenen:
Maar nu vraag ik mij of hoe ik de laatst getekende lijn ( Of ander figuur ) verwijder? Dus niet alle lijnen maar alleen de laatst getekende lijn. Ik weet wel hoe ik alles verwijder, maar goed dat wil ik dus niet.
Heeft iemand een idee hoe je dat snel doet?
Visual Basic:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
| Imports Microsoft.VisualBasic.PowerPacks Public Class Form1 Dim x As Integer Dim y As Integer Dim x1 As Integer Dim y1 As Integer Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load DrawRectangle() DrawCircle() DrawLine() End Sub Private Sub DrawRectangle() Dim canvas As New Microsoft.VisualBasic.PowerPacks.ShapeContainer Dim rect1 As New Microsoft.VisualBasic.PowerPacks.RectangleShape ' Set the form as the parent of the ShapeContainer. canvas.Parent = Me ' Set the ShapeContainer as the parent of the RectangleShape. rect1.Parent = canvas ' Set the location and size of the rectangle. rect1.Left = 10 rect1.Top = 10 rect1.Width = 300 rect1.Height = 100 End Sub Private Sub DrawCircle() Dim canvas As New ShapeContainer ' To draw an oval, substitute ' OvalShape for RectangleShape. Dim theShape As New OvalShape ' Set the form as the parent of the ShapeContainer. canvas.Parent = Me ' Set the ShapeContainer as the parent of the Shape. theShape.Parent = canvas ' Set the size of the shape. theShape.Size = New System.Drawing.Size(200, 300) ' Set the location of the shape. theShape.Location = New System.Drawing.Point(100, 100) ' To draw a rounded rectangle, add the following code: End Sub Private Sub DrawLine() Dim canvas As New ShapeContainer Dim theLine As New LineShape ' Set the form as the parent of the ShapeContainer. canvas.Parent = Me ' Set the ShapeContainer as the parent of the LineShape. theLine.Parent = canvas ' Set the starting and ending coordinates for the line. theLine.StartPoint = New System.Drawing.Point(x, y) theLine.EndPoint = New System.Drawing.Point(x1, y1) End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click x = TextBox1.Text y = TextBox2.Text x1 = TextBox3.Text y1 = TextBox4.Text DrawLine() End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click End Sub End Class |
Maar nu vraag ik mij of hoe ik de laatst getekende lijn ( Of ander figuur ) verwijder? Dus niet alle lijnen maar alleen de laatst getekende lijn. Ik weet wel hoe ik alles verwijder, maar goed dat wil ik dus niet.
Heeft iemand een idee hoe je dat snel doet?
[ Voor 0% gewijzigd door NMe op 08-04-2010 14:40 ]