CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Apr 2003
    Posts
    322

    Passing a frame as a Control

    I want to pass a Frame control to a sub, so that I can enable/disable all controls
    that are contained on the frame, with a simple loop

    I've already set the container property of each control to the Frame.
    (this code not shown for simplicity)

    Now I just need to loop through all the controls and enable/disable them.

    I don't know how to pass the Frame as a control or object, in the actual Call.

    private const CTRLS_ENABLED AS BOOLEAN = True

    'caller
    SetControls(frmColors, CTRLS_ENABLED)
    ' this call doesn't work, because it passes the Caption propertuy by default

    'Private Sub SetControls(Parent As Control, CtrlState As Boolean)
    'Private Sub SetControls(Parent As Object, CtrlState As Boolean)
    Private Sub SetControls(Parent As Frame, CtrlState As Boolean)

    Dim Ctrl As Control

    On Error Resume Next
    For Each Ctrl In Parent
    Ctrl.Enabled = CtrlState
    Next Ctrl

    End Sub

    Can someone help me out here ?

    thanks

  2. #2
    Join Date
    Dec 2001
    Posts
    6,332

    Re: Passing a frame as a Control

    The easy way is to disable the frame only, which will prevent the controls on it from being accessed. However, they won't actually appear disabled. You can iterate through the form's controls collection, and disable only those which are in the frame.
    Please remember to rate the posts and threads that you find useful.
    How can something be both new and improved at the same time?

  3. #3
    Join Date
    Apr 2003
    Posts
    322

    Re: Passing a frame as a Control

    Quote Originally Posted by WizBang
    The easy way is to disable the frame only, which will prevent the controls on it from being accessed. However, they won't actually appear disabled. You can iterate through the form's controls collection, and disable only those which are in the frame.
    I will do that, for the future, I would still like to know how to pass a Frame, so I can iterate through it's properties.

  4. #4
    Join Date
    Apr 2003
    Posts
    322

    Re: Passing a frame as a Control

    Quote Originally Posted by WizBang
    The easy way is to disable the frame only, which will prevent the controls on it from being accessed. However, they won't actually appear disabled. You can iterate through the form's controls collection, and disable only those which are in the frame.
    When I disable the frame, the controls on it ARE disabled, but not greyed out. THat is, they don't look disabled.

    Why is that ?

  5. #5
    Join Date
    Dec 2001
    Posts
    6,332

    Re: Passing a frame as a Control

    Quote Originally Posted by cappy2112
    When I disable the frame, the controls on it ARE disabled, but not greyed out. THat is, they don't look disabled.

    Why is that ?
    Yes, that's what I said. As for why, I suppose it's just because the controls aren't actually disabled. Think of it like a form which is disabled - same effect. It's just how windows works.
    Please remember to rate the posts and threads that you find useful.
    How can something be both new and improved at the same time?

  6. #6
    Join Date
    Jan 2000
    Location
    Olen, Belgium
    Posts
    2,477

    Re: Passing a frame as a Control

    I think the problem lies in the declaration of the SetControls function you wrote.
    Make sure you explicitly declare the parameter that accepts the frame to either Frame or Object. Not declaring the parameter will turn it into a variant, makeing it convert the variant into the default property of the frame (which is the caption), in this case a string.
    Tom Cannaerts
    email: [email protected]
    www.tom.be (dutch site)

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

Featured