S
Starbuck
Hi
I have created an array of buttons thus (see below). The buttons appear on
the form fine.
The only thing I cannot figure is how to capture the click and do a action
depending on which
button in thr array was clicked.
Thanks for any advise
Regards
For cnt = 0 To 7
backButtons.AddNewButton()
backButtons(cnt).Parent = ctab1
backButtons(cnt).Left = 250
backButtons(cnt).Top = 24 * (cnt + 1)
backButtons(cnt).Height = 22
backButtons(cnt).Width = 80
backButtons(cnt).Text = "BackGround"
Next cnt
backButtons = New ButtonArray(Me)
Dim backButtons As ButtonArray
From this class
Public Class ButtonArray
Inherits System.Collections.CollectionBase
Private ReadOnly HostForm As System.Windows.Forms.Form
Public Function AddNewButton() As System.Windows.Forms.Button
Dim aButton As New System.Windows.Forms.Button
Me.List.Add(aButton)
HostForm.Controls.Add(aButton)
aButton.Top = Count * 25
aButton.Width = 50
aButton.Left = 140
aButton.Tag = Me.Count
aButton.Text = "Button " & Me.Count.ToString
Return aButton
End Function
Public Sub New(ByVal host As System.Windows.Forms.Form)
HostForm = host
Me.AddNewButton()
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()
If Me.Count > 0 Then
HostForm.Controls.Remove(Me(Me.Count - 1))
Me.List.RemoveAt(Me.Count - 1)
End If
End Sub
End Class
I have created an array of buttons thus (see below). The buttons appear on
the form fine.
The only thing I cannot figure is how to capture the click and do a action
depending on which
button in thr array was clicked.
Thanks for any advise
Regards
For cnt = 0 To 7
backButtons.AddNewButton()
backButtons(cnt).Parent = ctab1
backButtons(cnt).Left = 250
backButtons(cnt).Top = 24 * (cnt + 1)
backButtons(cnt).Height = 22
backButtons(cnt).Width = 80
backButtons(cnt).Text = "BackGround"
Next cnt
backButtons = New ButtonArray(Me)
Dim backButtons As ButtonArray
From this class
Public Class ButtonArray
Inherits System.Collections.CollectionBase
Private ReadOnly HostForm As System.Windows.Forms.Form
Public Function AddNewButton() As System.Windows.Forms.Button
Dim aButton As New System.Windows.Forms.Button
Me.List.Add(aButton)
HostForm.Controls.Add(aButton)
aButton.Top = Count * 25
aButton.Width = 50
aButton.Left = 140
aButton.Tag = Me.Count
aButton.Text = "Button " & Me.Count.ToString
Return aButton
End Function
Public Sub New(ByVal host As System.Windows.Forms.Form)
HostForm = host
Me.AddNewButton()
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()
If Me.Count > 0 Then
HostForm.Controls.Remove(Me(Me.Count - 1))
Me.List.RemoveAt(Me.Count - 1)
End If
End Sub
End Class