-
Oct 28th, 2014, 08:24 AM
#1
Thread Starter
New Member
[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
-
Oct 28th, 2014, 08:26 AM
#2
Re: How to Check If Control Is In Frame
If TypeOf theControl.Container Is Frame Then ...
-
Oct 28th, 2014, 08:29 AM
#3
Thread Starter
New Member
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).
-
Oct 28th, 2014, 08:30 AM
#4
Thread Starter
New Member
Re: How to Check If Control Is In Frame
Nevermind, it was a different issue in the program. Thank you
-
Oct 28th, 2014, 09:27 AM
#5
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|