How can i add objects such as buttons, labels or textboxes at runtime?

Recommended Answers

All 2 Replies

Hi
Example to adding control at runtime

Option Explicit
' Declare object variable as CommandButton.
Private WithEvents cmdObject As CommandButton 

Private Sub Form_Load()
   Set cmdObject = Form1.Controls.Add("VB.CommandButton", "cmdOne")
   cmdObject.Visible = True
   cmdObject.Caption = "Dynamic CommandButton"
End Sub

Private Sub cmdObject_Click()
    MsgBox "This is a dynamically added control"
End Sub

Yes u can, i think selvaganapathy was given the best answer :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.