Results 1 to 4 of 4

Thread: Create Multiple Controls At Runtime

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 1999
    Location
    belgium
    Posts
    74

    Question

    Hello,

    How can I put multiple controls to a form at runtime?
    For instance:

    At runtime I want to put 2 textboxes, 1 combobox and 1 checkbox


    Thanks

  2. #2
    Frenzied Member sebs's Avatar
    Join Date
    Sep 2000
    Location
    Aylmer,Qc
    Posts
    1,606
    Go look that thread

  3. #3

    Thread Starter
    Lively Member
    Join Date
    May 1999
    Location
    belgium
    Posts
    74
    Yes, I knew that already. But with this code, you can only put one object to the form.

    How can I put some more objects to my form?

  4. #4
    Frenzied Member sebs's Avatar
    Join Date
    Sep 2000
    Location
    Aylmer,Qc
    Posts
    1,606
    Code:
    Option Explicit
    ' Remarks:
    ' Dynamically add a new button to the form. The
    ' item to add, a button in this case, must be a
    ' member of the VB object as displayed in the
    ' Object Browser.  The second parameter is the
    ' the new control's name.
    '
    Private WithEvents btnObj As CommandButton
    
    Private Sub btnObj_Click()
    '
    ' Respond to the new button's Click event.
    '
        MsgBox "This button was added at run time!"
    End Sub
    
    Private Sub cmdAdd_Click()
     
        Set text1 = Controls.Add("VB.TextBox", "text1")
        '
        With text1
            .Visible = True
            .Text = "&Dynamically Added Text"
            .Top = 0
            .Left = 0
            .Width = 2400
            .Height = 500
        End With
    
        Set text2 = Controls.Add("VB.TextBox", "text2")
        '
        With text2
            .Visible = True
            .Text = "&Dynamically Added Text"
            .Top = 0
            .Left = 0
            .Width = 2400
            .Height = 500
        End With
        Set cbo1 = Controls.Add("VB.ComboBox", "cbo1")
        '
        With cbo1
            .Visible = True
            .Caption = "&Dynamically Added Combobox"
            .Top = 0
            .Left = 0
            .Width = 2400
            .Height = 500
        End With
        Set Chk1 = Controls.Add("VB.CheckBox", "Chk1")
        '
        With Chk1
            .Visible = True
            .Caption = "&Dynamically Added Checkbox"
            .Top = 0
            .Left = 0
            .Width = 2400
            .Height = 500
        End With
    
    End Sub
    What seem to be the problem!
    Just change the top,left,width and height

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