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 Frame that uses a CheckBox in its caption that determines whether the items it contains are enabled in Visual Basic 6
DescriptionThis example shows how to make a Frame that uses a CheckBox in its caption that determines whether the items it contains are enabled in Visual Basic 6.
KeywordsFrame, CheckBox, enable, disable, Visual Basic 6, VB 6, Visual Basic, VB
CategoriesControls
 
As design time, set the Frame's Caption to an empty string and position a CheckBox so it looks like it is the Frame's caption.

The CheckBox's Click event handler calls subroutine ManageCheckFrame, which does all of the interesting work.

 
Private Sub chkBreakfast_Click()
    ManageCheckFrame chkBreakfast, frBreakfast
End Sub

Private Sub chkLunch_Click()
    ManageCheckFrame chkLunch, frLunch
End Sub

Private Sub ManageCheckFrame(ByVal chk As CheckBox, ByVal _
    fr As Frame)
Dim ctl As Control

    ' Enable or disable the Frame.
    fr.Enabled = (chk.Value = Checked)

    If fr.Enabled Then
        ' Color the CheckBox.
        'chk.ForeColor = vbButtonText

        ' Color the controls in the Frame.
        For Each ctl In Controls
            If ctl.Container Is fr Then
                ctl.ForeColor = vbButtonText
            End If
        Next ctl
    Else
        ' Color the CheckBox.
        'chk.ForeColor = vbGrayText

        ' Color the controls in the Frame.
        For Each ctl In Controls
            If ctl.Container Is fr Then
                ctl.ForeColor = vbGrayText
            End If
        Next ctl
    End If
End Sub
 
Subroutine ManageCheckFrame enables or disables the Frame depending on the value of the CheckBox. It then loops through all of the form's controls and sets the ForeColor property for those that are contained in the Frame appropriately.

If you like, you can also color the CheckBox so it's gray when unchecked. This may be a bit confusing to users, however, because the CheckBox is not disabled.

Thanks to Joe Sova for suggesting using the system color constants vbGrayText and vbButtonText instead of hard-coded color values.

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