Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleMake a form that contains other forms in a PictureBox
DescriptionThis example shows how to make a form that contains other forms in a PictureBox in Visual Basic 6. It uses SetPicture to reparent the sub form.
KeywordsForm, subform, SetParent
CategoriesControls
 
The program uses SetParent to put new forms inside the PictureBox. When the main form unloads, the program unloads its subforms.
 
Private Sub Command1_Click()
Dim frm As Form2

    Set frm = New Form2
    SetParent frm.hWnd, Picture1.hWnd
    frm.Show
End Sub

' Unload all the Form2 forms.
Private Sub Form_Unload(Cancel As Integer)
Static unloading As Boolean

Dim i As Integer

    If unloading Then Exit Sub

    unloading = True
    For i = Forms.Count - 1 To 0 Step -1
        Unload Forms(i)
    Next i
End Sub
 
The subforms behave a bit strangely when the user moves them, shrinks them, resizes the parent PictureBox, etc. You may want to remove their borders and arrange them explicitly in code.
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated