how can i load a button for example inside a usercontrol in runtime?
Printable View
how can i load a button for example inside a usercontrol in runtime?
The same way you would do it on the form:
Note: you can also use control array.Code:'add this code to your user control
Option Explicit
Dim WithEvents btn As CommandButton
'assuming your user control has a button "Command1" - otherwise use this part of code elsewhere
Private Sub Command1_Click()
Set btn = UserControl.Controls.Add("VB.CommandButton", "btnTemp")
btn.Move 100, 100
btn.Caption = "Test"
btn.Visible = True
End Sub
Private Sub btn_Click()
MsgBox "Hello World!"
End Sub