I am trying to create an app that will allow a user to add buttons with a provided name to a form. However, I am unsure how to create the button using the user-provided value.
I have tried this
Dim Button_ & ButtonName As New Button
This obviously does not work, does anyone know if this is possible and if so, how I would go about doing it.
I would also need to generate a handler for the button so that I can make it function. For example,
Private Sub button_ & ButtonName & _Click(sender As Object, e As EventArgs) Handles Button_ & ButtonName & .Click
dim btn as new Button() with { .Name = ButtonName, .Text = ButtonName } AddHandler btn.Click, AddressOf SomePredefinedHandler. Or use a Lambda:AddHandler btn.Click, Sub(obj, args) End Sub(End Subgoes on a new line). Better use the firstAddHandlersyntax. You probably want to add these controls to a collection (e.g.,List(Of Button)).