How to dynamic add controls

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,
Can anybody tell me how to add controls (dropdown list or textbox) to a form
Thanks in advance
dd
 
ddt said:
Hi,
Can anybody tell me how to add controls (dropdown list or textbox) to a form?
Thanks in advance.
dd

The best way to learn how to do it is to drop a few controls on a form in
the IDE, and then look at the automatically generated code... You will see
then how controls are instantiated and added to the form...

You'll have to use the AddHandler command to handle control events, but
otherwise, it's pretty much the same as automatically generated code.

HTH

Lorne
 
* =?Utf-8?B?ZGR0?= said:
Can anybody tell me how to add controls (dropdown list or textbox) to a form?

Sample for a button control:

\\\
Dim btn As New Button()
AddHandler btn.Click, AddressOf Me.btn_Click
Me.Controls.Add(btn)
///

Add the handler code:

\\\
Private Sub btn_Click( _
ByVal sender As Object, _
ByVal e As EventArgs _
)
MsgBox("Clicked!")
End Sub
///
 
Thanks, but my question is how to add them in run time, i.e. add some (not just one) controls in run time just like control array in VB6.

Thanks.
 
Thanks, but my question is how to add them in run time, i.e. add some (not just one) controls in run time just like control array in VB6.

Thanks.

Dim ControlCount as integer
Dim MyTextBox as TextBox

For ControlCount = 0 to 9
MyTextBox = New TextBox
MyForm.Controls.Add(MyTextBox)
'Add any handlers (See the AddHandler method)
AddHandler MyText.TextChanged, AddressOf MyText_TextChanged
Next

Public Sub MyText_TextChanged(ByVal sender As Object, ByVal e As
EventArgs)
'Add code for text changed on dynamically added textboxes
End Sub

Hope this explains a bit more.

Cheers

Tom
 
Back
Top