I can i add control on my form at run time.
Printable View
I can i add control on my form at run time.
This will add a textbox to the form
Code:Public WithEvents Text1 As TextBox
Private Sub Command1_Click()
Set Text1 = Form1.Controls.Add("VB.TextBox", "Text1")
Text1.Visible = True
End Sub
If you have VB5, then use CreatewindowEx API.
Code:Private Declare Function CreateWindowEx Lib "user32" Alias "CreateWindowExA" (ByVal dwExStyle As Long, ByVal lpClassName As String, ByVal lpWindowName As String, ByVal dwStyle As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hWndParent As Long, ByVal hMenu As Long, ByVal hInstance As Long, lpParam As Any) As Long
Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Private Const WS_CHILD = &H40000000
Dim btnHwnd As Long
Private Sub Form_Load()
btnHwnd = CreateWindowEx(0, "Button", "Button1", WS_CHILD, 32, 32, 64, 64, hwnd, 0, App.hInstance, ByVal 0)
ShowWindow btnHwnd, 1
End Sub