Results 1 to 5 of 5

Thread: [RESOLVED] How to Check If Control Is In Frame

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2014
    Posts
    13

    Resolved [RESOLVED] How to Check If Control Is In Frame

    I wrote a subroutine that iterates through all the items in a form and then moves them all together. However, I do not want it to move the objects in frames (as then they are not in their proper position in the frame). I was thinking I may need a way to check if the control is in the frame. Does anyone know how to do this? I am having difficulty finding an answer. Thank you in advance

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: How to Check If Control Is In Frame

    If TypeOf theControl.Container Is Frame Then ...
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #3

    Thread Starter
    New Member
    Join Date
    Oct 2014
    Posts
    13

    Re: How to Check If Control Is In Frame

    I tried this, but then it thought that all objects on the form were in the frame (ie. it didn't move anything).

  4. #4

    Thread Starter
    New Member
    Join Date
    Oct 2014
    Posts
    13

    Re: How to Check If Control Is In Frame

    Nevermind, it was a different issue in the program. Thank you

  5. #5
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    9,853

    Re: [RESOLVED] How to Check If Control Is In Frame

    Hey Dill,

    Just slightly off-topic, but it's always been VERY irritating to me that disabling the frame doesn't also disable all its children. You can't get to them, but they don't "appear" disabled. Here's code that does that. If you mess with frames a lot, you'll wind up wanting this:

    Code:
    Public Property Let FrameAndChildrenEnabled(fra As Frame, bEnableStatus As Boolean)
        ' This enables/disables all child controls of a specific frame.
        Dim i As Integer
        Dim frm As Form
        '
        Set frm = fra.Parent
        For i = 0 To frm.Controls.Count - 1
            If bControlHasContainer(frm.Controls(i)) Then
                If frm.Controls(i).Container Is fra Then
                    '
                    ' Recursion to handle frames within frames.
                    If TypeOf frm.Controls(i) Is Frame Then
                        FrameAndChildrenEnabled(frm.Controls(i)) = bEnableStatus
                    Else
                        On Error Resume Next ' Not all controls have an enabled property.
                        frm.Controls(i).Enabled = bEnableStatus
                        On Error GoTo 0
                    End If
                End If
            End If
        Next i
        fra.Enabled = bEnableStatus
    End Property
    
    Public Function bControlHasContainer(TheControl As Control) As Boolean
        '
        Dim TheContainer As Control
        On Error GoTo NoContainer
        Set TheContainer = TheControl.Container
        bControlHasContainer = True
        Exit Function
        '
    NoContainer:
        bControlHasContainer = False
        Exit Function
        '
    End Function

Tags for this Thread

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