-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathButtonArray.vb
More file actions
61 lines (60 loc) · 2.46 KB
/
ButtonArray.vb
File metadata and controls
61 lines (60 loc) · 2.46 KB
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
Public Class ButtonArray
Inherits System.Collections.CollectionBase
Private ReadOnly HostForm As System.Windows.Forms.Form
Public Function AddNewButton(ByVal ButtonText As String) As System.Windows.Forms.Button
' Create a new instance of the Button class.
Dim aButton As New System.Windows.Forms.Button()
' Add the button to the collection's internal list.
Me.List.Add(aButton)
' Add the button to the controls collection of the form
' referenced by the HostForm field.
HostForm.Controls.Add(aButton)
' Set intial properties for the button object.
aButton.Top = Count * 22
aButton.Left = 100
aButton.Tag = Me.Count
aButton.Text = ButtonText
' Visual Basic
AddHandler aButton.Click, AddressOf ClickHandler
Return aButton
End Function
Public Function AddNewButton(ByVal Left As Integer, ByVal ButtonText As String) As System.Windows.Forms.Button
Dim aButton As New System.Windows.Forms.Button()
' Add the button to the collection's internal list.
Me.List.Add(aButton)
' Add the button to the controls collection of the form
' referenced by the HostForm field.
HostForm.Controls.Add(aButton)
' Set intial properties for the button object.
aButton.Top = Count * 20
aButton.Left = Left
aButton.Tag = Me.Count
aButton.Text = ButtonText
aButton.Width = 250
aButton.Height = 22
' Visual Basic
AddHandler aButton.Click, AddressOf ClickHandler
Return aButton
End Function
Public Sub New(ByVal host As System.Windows.Forms.Form)
HostForm = host
End Sub
Default Public ReadOnly Property Item(ByVal Index As Integer) As System.Windows.Forms.Button
Get
Return CType(Me.List.Item(Index), System.Windows.Forms.Button)
End Get
End Property
Public Sub Remove()
' Check to be sure there is a button to remove.
If Me.Count > 0 Then
' Remove the last button added to the array from the host form
' controls collection. Note the use of the default property in
' accessing the array.
HostForm.Controls.Remove(Me(Me.Count - 1))
Me.List.RemoveAt(Me.Count - 1)
End If
End Sub
Public Sub ClickHandler(ByVal sender As Object, ByVal e As System.EventArgs)
' if you want to do something on click
End Sub
End Class