Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleCreate new controls using Controls.Add
DescriptionThis example shows how to create new controls using Controls.Add in Visual Basic 6.
KeywordsControls.Add, controls, create controls
CategoriesControls, Tips and Tricks
 
Thanks to Saurav.

The program's buttons use the Controls.Add method to create new TextBox, Label, and CommandButton controls.

 
Dim txt As TextBox
Dim leb As Label
Dim com As CommandButton

Private Sub Command1_Click()
    Set txt = Controls.Add("VB.TextBox", "txt" & tn & "")
    Set txt.Container = Form1
    txt.Move 500, 1400 + tc, 1200, 350
    txt.Visible = True
    txt.Text = "TextBox" & tn & ""
    tc = tc + 1000
    tn = tn + 1
End Sub

Private Sub Command2_Click()
    Set leb = Controls.Add("VB.Label", "leb" & ln & "")
    Set leb.Container = Form1
    leb.Move 3000, 1400 + lc, 1200, 350
    leb.Visible = True
    leb.Caption = "Label" & ln & ""
    lc = lc + 1000
    ln = ln + 1
End Sub

Private Sub Command3_Click()
    Set com = Controls.Add("VB.CommandButton", "com" & cn & _
        "")
    Set com.Container = Form1
    com.Move 6400, 1400 + cc, 1200, 350
    com.Visible = True
    com.Caption = "Command" & cn & ""
    cc = cc + 1000
    cn = cn + 1
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated