Results 1 to 3 of 3

Thread: Spawning controls

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2001
    Posts
    485

    Thumbs down [unresolved]

    Alright, I bet most of you know how to spawn controls on a form already, right?

    But now, I wanted to spawn controls into, let say, a Frame, or a picturebox...

    How to accomplish that without putting in any controls into the Frame/picturebox earlier in design time.....

    Let's make it that both the frame/picturebox were spawned as well.


    Thanks

    Harddisk
    Last edited by Harddisk; Oct 11th, 2005 at 05:07 AM.

  2. #2
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    Here ya go:
    Code:
    Option Explicit
    Dim WithEvents fraFrame As Frame
    Dim WithEvents txtBox As TextBox
    
    Private Sub Command1_Click()
        Set fraFrame = Me.Controls.Add("VB.Frame", "Frame")
        With fraFrame
            .Top = 100
            .Left = 100
            .Width = 3000
            .Height = 3000
            .Visible = True
        End With
        
        Set txtBox = Me.Controls.Add("VB.TextBox", "Text")
        Set txtBox.Container = fraFrame
        With txtBox
            .Top = 200
            .Left = 200
            .Visible = True
        End With
    End Sub
    
    Private Sub Command2_Click()
        fraFrame.Move 2000
    End Sub

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2001
    Posts
    485
    Code:
      Load frmFirst
      Option Explicit
      Dim frmFirst As New Form2
      Dim WithEvents txtFirstO As TextBox
    
      Load frmFirst
    ''  Set frmFirst = Me.Controls.Add("VB.Form", "frmFirst")
      With frmFirst
        .Top = 120
        .Left = 120
        .Height = 4500
        .Width = 4500
        .Caption = "First file output"
        .Visible = True
      End With
      
      Set txtFirstO = frmFirst.Controls.Add("VB.TextBox", "txtFirstO")
      With txtFirstO
        .Top = 120
        .Left = 120
        .Height = frmFirst.Height - .Top - 480
        .Width = frmFirst.Width - .Left - 240
    '    .MultiLine = True
        .Locked = True
    '    .ScrollBars = vbBoth
        .Visible = True
      End With
      frmFirst.Show
    Please have a look, those with single quote, are read-only when I m trying to define it, except for the Set frmFirst ... line

    How do I deal with that?

    I managed to spawn 2 new forms out of Form2 (a new form created durng design-time)

    How about spawning new forms during run-time without extra forms in design time. If i were to use Form1, then all the controls in form1 will be inherited as well.

    Thanks

    Harddisk

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