2012-03-30 15 views
1

Ich habe eine OCX, die so ziemlich wie ein Rahmen fungiert. Ich möchte in der Lage sein, die Komponente zu aktivieren/deaktivieren und alle anderen Steuerelemente, die innerhalb des Rahmens platziert sind, ebenfalls zu deaktivieren. Gibt es einen Weg, dies zu erreichen?VB6 OCX erstellen Aktivieren/Deaktivieren Sie alle Steuerelemente in

Dank

+0

Durch das Deaktivieren eines Containers werden die enthaltenen/untergeordneten Steuerelemente auch logisch deaktiviert. Sie werden normal aussehen, können aber nicht interagiert werden. – Deanna

Antwort

4

ich einige Hilfsmethoden machte dies und mehr zu erreichen. Fühlen Sie sich frei, es zu benutzen und zu ändern!

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