VagabondSW
Regular
- Joined
- Feb 19, 2005
- Messages
- 66
I need a bit of a kick-in-the-rear to get me on the right track. I have programmatically added buttons to a Panel, but I now need to handle the click event of each of those buttons.
I have a sub-routine that creates an instance of a Button and adds it to the Panel.Controls collection. Once the end of that sub-routine is reached, the instance of those buttons are out of scope.
Is there a way to programmatically create the event handlers for the buttons in the Panel.Controls collection or do I need to Declare a Button Array and add them to that in order to support event handling? Does that make sense?
I have a sub-routine that creates an instance of a Button and adds it to the Panel.Controls collection. Once the end of that sub-routine is reached, the instance of those buttons are out of scope.
Is there a way to programmatically create the event handlers for the buttons in the Panel.Controls collection or do I need to Declare a Button Array and add them to that in order to support event handling? Does that make sense?
Visual Basic:
Private Sub MakePanelControlTop()
Dim buttonAdd As New Button
With buttonAdd
.FlatStyle = FlatStyle.Flat
.Name = Me.BUTTON_NAME_ADD
.Text = Me.BUTTON_TEXT_ADD
End With
PanelControlTop.Controls.Add(buttonAdd)
Me.MakeToolTip(buttonAdd, Me.TOOLTIP_TEXT_BTNADD)
Dim buttonRemove As New Button
With buttonRemove
.FlatStyle = FlatStyle.Flat
.Name = Me.BUTTON_NAME_REMOVE
.Text = Me.BUTTON_TEXT_REMOVE
End With
PanelControlTop.Controls.Add(buttonRemove)
Me.MakeToolTip(buttonRemove, Me.TOOPTIP_TEXT_BTNREMOVE)
Dim buttonClear As New Button
With buttonClear
.FlatStyle = FlatStyle.Flat
.Name = Me.BUTTON_NAME_CLEAR
.Text = Me.BUTTON_TEXT_CLEAR
End With
PanelControlTop.Controls.Add(buttonClear)
Me.MakeToolTip(buttonClear, Me.TOOLTIP_TEXT_BTNCLEAR)
Dim buttonApply As New Button
With buttonApply
.FlatStyle = FlatStyle.Flat
.Name = Me.BUTTON_NAME_APPLY
.Text = Me.BUTTON_TEXT_APPLY
End With
PanelControlTop.Controls.Add(buttonApply)
Me.MakeToolTip(buttonApply, Me.TOOLTIP_TEXT_BTNAPPLY)
End Sub