Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
 
 
 
500MB 27GB Web Hosting - $9.95/Month
 
 
 
 
 
Old Pages
 
Old Index
Site Map
What's New
 
Books
How To
Tips & Tricks
Tutorials
Stories
Performance
Essays
Links
Q & A
New in VB6
Free Stuff
Pictures
 
 
 
TitleDynamically create controls at runtime using Controls.Add and place them in a scrolled window
KeywordsLoad, dynamic control, runtime, Controls.Add
CategoriesControls
 
Use the Controls collection's Add method to create the new control specifying the inner PictureBox as its parent. Use scroll bars to allow the user to move the PictureBox inside another PictureBox to make the inner one scroll.
 
' Add a new control to the inner PictureBox.
Private Sub mnuControlsAdd_Click()
Dim ctl As TextBox
Dim prev As TextBox

    ' Create the control.
    m_NumControls = m_NumControls + 1
    Set ctl = Controls.Add( _
        "VB.TextBox", _
        "Text" & Format$(m_NumControls), _
        picInner)

    ' Position the control.
    Set prev = Controls("Text" & Format$(m_NumControls - 1))
    ctl.Move prev.Left, _
        prev.Top + prev.Height + 30, _
        prev.Width, prev.Height
    ctl.Text = ctl.Name

    ' Size picInner to hold the control.
    picInner.Move 0, 0, _
        ctl.Left + ctl.Width + 120, _
        ctl.Top + ctl.Height + 120

    ' Display the control.
    ctl.Visible = True

    ' Rearrange the scroll bars.
    ArrangeScrollBars
End Sub
 
For a similar example that uses Load to make a control array instead of using Controls.Add, see How To: Dynamically create controls at runtime using Load and place them in a scrolled window.

For details on making a scrolled window, see How To: Make a scrolled window.

 
 
Copyright © 1997-2003 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated