TripleState 属性、ToggleButton 控件示例

以下示例使用 TripleState 属性允许 Null 作为 CheckBoxToggleButton 的法定值。

The user controls the value of TripleState through ToggleButton2. The user can set the value of a CheckBox or ToggleButton based on the value of TripleState.

若要使用此示例,请将此示例代码复制到窗体的声明部分。 确保该窗体包含:

  • 一个名为"CheckBox1"的 CheckBox
  • 一个名为"ToggleButton1"的 ToggleButton
  • 一个名为"ToggleButton2"的 ToggleButton
Private Sub UserForm_Initialize() 
 CheckBox1.Caption = "Value is True" 
 CheckBox1.Value = True 
 CheckBox1.TripleState = False 
 
 ToggleButton1.Caption = "Value is True" 
 ToggleButton1.Value = True 
 ToggleButton1.TripleState = False 
 
 ToggleButton2.Value = False 
 ToggleButton2.Caption = "Triple State Off" 
End Sub 
 
Private Sub ToggleButton2_Click() 
 If ToggleButton2.Value = True Then 
 ToggleButton2.Caption = "Triple State On" 
 CheckBox1.TripleState = True 
 ToggleButton1.TripleState = True 
 Else 
 ToggleButton2.Caption = "Triple State Off" 
 CheckBox1.TripleState = False 
 ToggleButton1.TripleState = False 
 End If 
End Sub 
 
Private Sub CheckBox1_Change() 
 If IsNull(CheckBox1.Value) Then 
 CheckBox1.Caption = "Value is Null" 
 ElseIf CheckBox1.Value = False Then 
 CheckBox1.Caption = "Value is False" 
 ElseIf CheckBox1.Value = True Then 
 CheckBox1.Caption = "Value is True" 
 End If 
End Sub 
 
Private Sub ToggleButton1_Change() 
 If IsNull(ToggleButton1.Value) Then 
 ToggleButton1.Caption = "Value is Null" 
 ElseIf ToggleButton1.Value = False Then 
 ToggleButton1.Caption = "Value is False" 
 ElseIf ToggleButton1.Value = True Then 
 ToggleButton1.Caption = "Value is True" 
 End If 
End Sub

支持和反馈

有关于 Office VBA 或本文档的疑问或反馈? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。