Results 1 to 3 of 3

Thread: [RESOLVED] How do you place dynamically created controls in a Frame?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Dec 2005
    Posts
    29

    Resolved [RESOLVED] How do you place dynamically created controls in a Frame?

    I can place dynamically created textbox and combobox on either form1 or form2 (see code below) but can't place them on a Frame within Form1 or Form2. How do you do this? Thanks much.

    This works:
    Set MyTextBox = Form1.Controls.Add("VB.TextBox", "MyTextBox" & CStr(Index))

    This does not:
    Set MyTextBox = Form1.Frame2.Controls.Add("VB.TextBox", "MyTextBox" & CStr(Index))



    Dim holder(4) As Object

    Private Property Get MyTextBox(ByVal Index As Integer) As TextBox
    Dim txt As TextBox
    On Error GoTo ER

    'Fetch the control for Index.
    Set MyTextBox = Form1.Controls("MyTextBox" & CStr(Index))

    Exit Property

    ER:

    'If the control for Index doesn't exist, create it.
    If Err.Number = 730 Then
    Set MyTextBox = Form1.Controls.Add("VB.TextBox", "MyTextBox" & CStr(Index))
    End If
    End Property

    Private Property Get MyComboBox(ByVal Index As Integer) As ComboBox
    Dim txt As ComboBox
    On Error GoTo ER

    'Fetch the control for Index.
    Set MyComboBox = Form1.Controls("MyComboBox" & CStr(Index))

    Exit Property

    ER:

    'If the control for Index doesn't exist, create it.
    If Err.Number = 730 Then
    Set MyComboBox = Form1.Controls.Add("VB.ComboBox", "MyComboBox" & CStr(Index))
    End If
    End Property

    'You can use it as you would any other control array, except that you don't have to explicitly load it:

    Private Sub Form_Load()
    Dim x As Integer

    Form2.Show

    For x = 1 To 4 Step 1

    If x = 2 Then

    With MyComboBox(x)
    Set holder(x) = MyComboBox(x)
    End With
    Else
    With MyTextBox(x)
    Set holder(x) = MyTextBox(x)
    End With

    End If

    With holder(x)
    .Visible = True
    .Top = x * 600
    .Text = x
    End With

    Next

    End Sub

  2. #2
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: How do you place dynamically created controls in a Frame?

    VB Code:
    1. Set MyTextBox.Container = Frame1

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Dec 2005
    Posts
    29

    Re: How do you place dynamically created controls in a Frame?

    Thanks!

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