Question How do I get my new (runtime) button to work/do stuff?

newguy

Well-known member
Joined
Jun 30, 2008
Messages
611
Location
Denver Co, USA
Programming Experience
1-3
Hi all, I figure out how to get my button to be created at runtime and even change the properties, now, how do I use it with a click event?

Here's the code:
VB.NET:
Public Class Form1
    Dim radiobutton As New RadioButton
    Dim radiobutton2 As New RadioButton
    Dim textbox10 As New TextBox
    Dim button1 As New Button
    Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged

        Select Case ListBox1.SelectedIndex
            Case 0                                                                              'MCI-0
                benchMarkFLP.Controls.Clear()
                GroupBox1.Controls.Clear()
                benchMarkFLP.Controls.Add(radiobutton)
                With radiobutton
                    .Text = "New"
                   
                End With
                benchMarkFLP.Controls.Add(radiobutton2)
                With radiobutton2
                    .Text = "Old"
                End With
                GroupBox1.Controls.Add(textbox10)
                With textbox10
                    .Multiline = True
                    .Dock = DockStyle.Fill
                    .BackColor = Color.LightBlue
                    .ReadOnly = True
                    .WordWrap = True
                    .Text = "HELLO"
                End With
            Case 1                                                                               'MCI-1
                benchMarkFLP.Controls.Clear()
                GroupBox1.Controls.Clear()
                benchMarkFLP.Controls.Add(button1)
                With button1
                    .Text = "Hi"
                    .Name = "button1"
                End With

        End Select
    End Sub
    
End Class
 
Check with AddHandler Statement in help, it has some explanation and a code sample.
 
Back
Top