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
 
 
 
 
 
TitleLoad new Frame controls and their contained controls
DescriptionThis example shows how to load new Frame controls and their contained controls in Visual Basic 6.
KeywordsFrame, control array, load
CategoriesControls
 
When you click the Copy button, the program makes a copy of a Frame control and the controls it contains. Each of the controls is contained in a control array. The program uses the Load statement to make new instances of the controls.

The main trick here is to set the new contained controls' Container properties to the new Frame that should hold them.

One other trick involves the optOccupation array of option buttons. When you create a new option button in the array, the checked state of the first button is cleared. The program saves this state so it can restore it after creating the new buttons.

 
Private Sub cmdCopy_Click()
Dim new_index As Integer
Dim next_opt As Integer
Dim i As Integer
Dim first_opt_value As Boolean

    ' Load the new frame.
    new_index = FrameA.UBound + 1
    Load FrameA(new_index)
    FrameA(new_index).Move FrameA(0).Left, FrameA(new_index _
        - 1).Top + FrameA(0).Height + 120
    FrameA(new_index).Visible = True

    ' Load FrameB.
    Load FrameB(new_index)
    Set FrameB(new_index).Container = FrameA(new_index)
    FrameB(new_index).Move FrameB(0).Left, FrameB(0).Top
    FrameB(new_index).Visible = True

    Load lblFirstName(new_index)
    Set lblFirstName(new_index).Container = _
        FrameB(new_index)
    lblFirstName(new_index).Visible = True

    Load txtFirstName(new_index)
    Set txtFirstName(new_index).Container = _
        FrameB(new_index)
    txtFirstName(new_index).Visible = True

    Load lblLastName(new_index)
    Set lblLastName(new_index).Container = FrameB(new_index)
    lblLastName(new_index).Visible = True

    Load txtLastName(new_index)
    Set txtLastName(new_index).Container = FrameB(new_index)
    txtLastName(new_index).Visible = True

    ' Load FrameC.
    Load FrameC(new_index)
    Set FrameC(new_index).Container = FrameA(new_index)
    FrameC(new_index).Move FrameC(0).Left, FrameC(0).Top
    FrameC(new_index).Visible = True

    ' Save the first option button's value.
    ' (Loading the new control clears its value.)
    first_opt_value = optOccupation(0).Value

    ' Load the option buttons.
    next_opt = optOccupation.UBound + 1
    For i = 0 To 2
        Load optOccupation(next_opt + i)
        Set optOccupation(next_opt + i).Container = _
            FrameC(new_index)
        optOccupation(next_opt + i).Caption = _
            optOccupation(i).Caption
        optOccupation(next_opt + i).Value = _
            optOccupation(i).Value
        optOccupation(next_opt + i).Move _
            optOccupation(i).Left, optOccupation(i).Top, _
            optOccupation(i).Width, optOccupation(i).Height
        optOccupation(next_opt + i).Visible = True
    Next i

    ' Restore the first option button's value.
    optOccupation(0).Value = first_opt_value
    optOccupation(next_opt).Value = first_opt_value

    ' Size the form to fit.
    Me.Height = FrameA(new_index).Top + _
        FrameA(new_index).Height + 120 + (Me.Height - _
        Me.ScaleHeight)
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated