VB6 Create OCX Включить / отключить все элементы управления внутри - PullRequest
1 голос
/ 30 марта 2012

Я создал OCX, который в значительной степени действует как фрейм.Я хочу иметь возможность включать / отключать компонент и иметь все другие элементы управления, размещенные внутри фрейма, которые также должны быть отключены.Есть ли способ сделать это?

Спасибо

1 Ответ

4 голосов
/ 30 марта 2012

Я сделал несколько утилитарных методов для достижения этой и других целей.Не стесняйтесь использовать и изменять его!

Option Explicit

Private Enum ControlProperty
    PropertyEnabled
    PropertyVisible
    PropertyText
End Enum

Public Sub SetEnabledPropertyForAllControlsInFrame(frmForm As Form, strFrameCaption As String, Optional booValue As Boolean)
    SetPropertyForAllControlsInFrame frmForm, strFrameCaption, PropertyEnabled, booValue
End Sub

Public Sub SetVisiblePropertyForAllControlsInFrame(frmForm As Form, strFrameCaption As String, Optional booValue As Boolean)
    SetPropertyForAllControlsInFrame frmForm, strFrameCaption, PropertyVisible, booValue
End Sub

Public Sub ClearAllTextBoxesInFrame(frmForm As Form, strFrameCaption As String, Optional strText As String)
    If IsMissing(strText) Then strText = vbNullString
    SetPropertyForAllControlsInFrame frmForm, strFrameCaption, PropertyText, strText
End Sub

Public Sub ClearAllTextBoxesInForm(frmForm As Form, Optional ExceptInFrame As Frame)
    Dim ctl As Control
    Dim strCaption As String

    If ExceptInFrame Is Nothing Then
        For Each ctl In frmForm.Controls
            If TypeOf ctl Is TextBox Then
                ctl.Text = vbNullString
            End If
        Next
    Else
        strCaption = ExceptInFrame.Caption
        ExceptInFrame.Caption = "xdgerviye246123nvasdmnvwe8"
        For Each ctl In frmForm.Controls
            If TypeOf ctl Is TextBox Then
                If TypeOf ctl.Container Is Frame Then
                    If Not ctl.Container.Caption = ExceptInFrame.Caption Then
                        ctl.Text = vbNullString
                    End If
                End If
            End If
        Next
        ExceptInFrame.Caption = strCaption
    End If

End Sub

Public Sub ClearAllCheckBoxesInForm(frmForm As Form)
    Dim ctl As Control

    For Each ctl In frmForm.Controls
        If TypeOf ctl Is CheckBox Then
            ctl.Value = vbUnchecked
        End If
    Next

End Sub

Private Sub SetPropertyForAllControlsInFrame(frmForm As Form, strFrameCaption As String, enuControlProperty As ControlProperty, varValue As Variant)
    Dim ctrl As Control
    Dim ctrl2 As Control
    For Each ctrl In frmForm.Controls
        If ctrl.Container.Caption = strFrameCaption Then
            Select Case enuControlProperty
                Case ControlProperty.PropertyEnabled
                    ctrl.Container.Enabled = varValue
                    ctrl.Enabled = varValue
                    If TypeOf ctrl Is TextBox Then
                        ctrl.BackColor = IIf(varValue = True, vbWindowBackground, vbButtonFace)
                    End If
                Case ControlProperty.PropertyVisible
                    ctrl.Container.Visible = varValue
                    ctrl.Visible = varValue
                Case ControlProperty.PropertyText
                    ctrl.Text = varValue
            End Select
            If TypeOf ctrl Is Frame Then
                SetPropertyForAllControlsInFrame frmForm, ctrl.Caption, enuControlProperty, varValue
            End If
        End If
    Next
End Sub
...