by Arnout de Vries (2 Submissions)
Category: VB function enhancement
Compatability: Visual Basic 3.0
Difficulty: Beginner
Date Added: Wed 3rd February 2021
Rating: (4 Votes)
When you disable a Frame then all controls in it are disabled to, nice feature, but to the users it still looks like if the controls as enabled.
So I wrote a little subroutine which en/disables all controls in a frame. Can be handy sometimes :-)
Option Explicit
Public Sub enableFrame(curFrame As Frame)
' purpose:
' set the .enabled property of all controls on a frame to
' the same state as the enabled state of the current frame
Dim ctl As Control
' Loop through all controls on the current form
For Each ctl In curFrame.Parent.Controls
On Error Resume Next ' error checking, because not every control has
' a container property
If ctl.Container.hWnd = curFrame.hWnd Then
If Err.Number = 0 Then ' if we didn't receive an error code, proceed
ctl.Enabled = curFrame.Enabled ' state of control same as Frame
If TypeOf ctl Is Frame Then ' if the control is a frame itself then
enableFrame ctl ' enter this procedure again for the current frame
End If
End If
End If
Next ctl
End Sub