Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: VB6
Expertise: Beginner
Nov 6, 2000

Create New Controls at Run Time


This undocumented feature of VB6 lets you create new controls at run time. In previous versions, one had to create a control array at design time in order to be able to add new controls in run time, which would then be the members of the control array. But in VB6, you can do it without a control array.

Paste following code in the Form's code window:
 
Option Explicit
Dim WithEvents mctlCommanButton As VB.CommandButton

Private Sub Form_Load()
    Set mctlCommanButton = Me.Controls.Add(VB.CommandButton,
CommandButton1)
    
    mctlCommanButton.Caption = Hi
    mctlCommanButton.Left = 10
    mctlCommanButton.Top = 10
    mctlCommanButton.Visible = True
End Sub

Private Sub mctlCommanButton_Click()
    MsgBox Hi
End Sub

Similarly, you can create any control. For example, for a Timer control, use VB.Timer instead of VB.CommandButton in the above code.
Jatin Shah
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date