Create Controls Dynamically (VB6) | CodeGuru

Create Controls Dynamically (VB6)

Author: Manoj Tuli Create a Control dynamically at Run time. Without using a Control Array. That is the control is not present at Design time But will appear at Run Time. option Explicit ‘ Dim withevents Cmd1 as CommandButton ‘ private Sub Form_Load() set Cmd1 = Controls.Add("vb.commandbutton", "Cmd1") Cmd1.Width = 2000 Cmd1.Top = me.Height / […]

Written By
CodeGuru Staff
CodeGuru Staff
Feb 3, 2004
1 minute read
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More

Author: Manoj Tuli

Create a Control dynamically at Run time. Without using a Control Array. That is the control is not present at Design time But will appear at Run Time.

screen-shot

option Explicit
'
Dim withevents Cmd1 as CommandButton
'
private Sub Form_Load()
  set Cmd1 = Controls.Add("vb.commandbutton", "Cmd1")
  Cmd1.Width = 2000
  Cmd1.Top = me.Height / 2 - Cmd1.Height / 2 - 100
  Cmd1.Left = me.Width / 2 - Cmd1.Width / 2 - 100
  Cmd1.Caption = "Dynamic Button"
  Cmd1.Visible = true
End Sub
'
private Sub Cmd1_click()
  MsgBox "I have been Created Dynamically at Run-time", _
    , "Dynamic Controls"
End Sub
'
CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.