Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
XML RSS Feed
 
 
 
 
 
 
 
 
Old Pages
 
Old Index
Site Map
What's New
 
Books
How To
Tips & Tricks
Tutorials
Stories
Performance
Essays
Links
Q & A
New in VB6
Free Stuff
Pictures
 
 
 
TitleCreate a new button using Controls.Add and respond to its click event
DescriptionThis example shows how to create a new button using Controls.Add and respond to its click event in Visual Basic 6.
Keywordsbutton, Controls.Add, event
CategoriesControls, Tips and Tricks
 
Declare a variable using the WithEvents keyword for the new button. Set this variable to the new button created with Controls.Add. Declaring the variable WithEvents means it gets events just like a button created at design time.
 
Private WithEvents new_button As CommandButton

Private Sub Command1_Click()
    Command1.Enabled = False

    Set new_button = Me.Controls.Add("VB.CommandButton", _
        "cmdNew")
    With new_button
        .Move Command1.Left, Command1.Top + Command1.Height _
            + 120
        .Caption = "New Button"
        .Visible = True
    End With
End Sub

Private Sub new_button_Click()
    MsgBox "Clicked"
End Sub
 
 
Copyright © 1997-2003 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated