VB6创建OCX启用/禁用内部的所有控件
我创建了一个OCX,它几乎可以作为一个框架。我希望能够启用/禁用组件,并将所有其他控件放置在框架内,以便也禁用。有没有办法做到这一点VB6创建OCX启用/禁用内部的所有控件,vb6,children,ocx,Vb6,Children,Ocx,我创建了一个OCX,它几乎可以作为一个框架。我希望能够启用/禁用组件,并将所有其他控件放置在框架内,以便也禁用。有没有办法做到这一点 谢谢我制作了一些实用的方法来实现这一点和更多。请随意使用和更改它 Option Explicit Private Enum ControlProperty PropertyEnabled PropertyVisible PropertyText End Enum Public Sub SetEnabledPropertyForAllCo
谢谢我制作了一些实用的方法来实现这一点和更多。请随意使用和更改它
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
我做了一些实用的方法来实现这一点和更多。请随意使用和更改它
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
禁用容器也会在逻辑上禁用包含的/子控件。它们看起来很正常,但无法与之交互。禁用容器在逻辑上也会禁用包含的/子控件。它们看起来很正常,但无法与之交互。