Adding Dynamic Controls with VB.Net

The following code shows how to dynamically add a control to a form in VB.Net.  In this case, a multiline textbox is added, some settings for ScrollBars and CharacterCasing are adjusted, and the textbox is set to call the MLTextbox_GotFocus function when the control receives focus


Dim dynText As New TextBox
With dynText
    .Name = "textWhatever"
    .Top = 40
    .Left = 40
    .Width = 80
    .Height = 60
    .Multiline = True
    .ScrollBars = ScrollBars.Vertical
    .CharacterCasing = CharacterCasing.Upper
End With
AddHandler dynText.Enter, AddressOf MLTextbox_GotFocus
Back to Top