News:

Choose a design and let our professionals help you build a successful website   - ITAcumens

Main Menu

create buttons at runtime

Started by nandagopal, May 18, 2009, 04:16 PM

Previous topic - Next topic

nandagopal

When you click the form's button, the following code executes. It make a new Button object, sets its text and size, and adds it to the flpButtons FlowLayoutPanel control's Children collection.

The code then uses AddHandler to make this button's Click event fire the same btnMakeButton_Click subroutine that created the button.


Private NumButtons As Integer = 1

Private Sub btnMakeButton_Click(ByVal sender As _
    System.Object, ByVal e As System.EventArgs) Handles _
    btnMakeButton.Click
    Dim btn As New Button()
    btn.Text = "Make Button " & NumButtons
    NumButtons += 1
    btn.Size = btnMakeButton.Size
    flpButtons.Controls.Add(btn)

    AddHandler btn.Click, AddressOf btnMakeButton_Click
End Sub



nomad

For your kind information this is C# section. Try to post it on C# too..Thanks