Results 1 to 3 of 3

Thread: Adding new control at runtime

  1. #1

    Thread Starter
    Frenzied Member sebs's Avatar
    Join Date
    Sep 2000
    Location
    Aylmer,Qc
    Posts
    1,606

    Question

    I can i add control on my form at run time.


  2. #2
    Frenzied Member Vlatko's Avatar
    Join Date
    Aug 2000
    Location
    Skopje, Macedonia
    Posts
    1,409
    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
    I am become death, the destroyer of worlds.
    mail:[email protected]

    • Visual Basic 6.0 & .NET
    • Visual C++ 6.0 & .NET
    • ASP
    • LISP
    • PROLOG
    • C
    • Pascal

  3. #3
    Guest
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width