IToggleProvider.Toggle 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
透過控制項狀態的切換循環。
public:
void Toggle();
public void Toggle ();
abstract member Toggle : unit -> unit
Public Sub Toggle ()
範例
下列範例針對可切換的自訂控制項,顯示這個方法的其中一個可能實作。
/// <summary>
/// Toggles the control.
/// </summary>
/// <remarks>
/// For this custom control the toggle state is reflected by the color
/// of the control. This is analogous to the CheckBox IsChecked property.
/// Green - ToggleState.On
/// Red - ToggleState.Off
/// Yellow - ToggleState.Indeterminate
/// </remarks>
void IToggleProvider.Toggle()
{
ToggleState toggleState =
customControl.toggleStateColor[customControl.controlColor];
// Invoke control method on separate thread to avoid clashing with UI.
// Use anonymous method for simplicity.
this.customControl.Invoke(new MethodInvoker(delegate ()
{
if (toggleState == ToggleState.On)
{
customControl.controlColor = Color.Red;
}
else if (toggleState == ToggleState.Off)
{
customControl.controlColor = Color.Yellow;
}
else if (toggleState == ToggleState.Indeterminate)
{
customControl.controlColor = Color.Green;
}
customControl.Refresh();
}));
}
''' <summary>
''' Toggles the control.
''' </summary>
''' <remarks>
''' For this custom control the toggle state is reflected by the color
''' of the control. This is analogous to the CheckBox IsChecked property.
''' Green - ToggleState.On
''' Red - ToggleState.Off
''' Yellow - ToggleState.Indeterminate
''' </remarks>
Private Sub Toggle() Implements IToggleProvider.Toggle
Dim toggleState As ToggleState = customControl.toggleStateColor(customControl.controlColor)
' Invoke control method on separate thread to avoid clashing with UI.
' Use anonymous method for simplicity.
Me.customControl.Invoke(New MethodInvoker(Sub()
If toggleState = Windows.Automation.ToggleState.On Then
customControl.controlColor = Color.Red
ElseIf toggleState = Windows.Automation.ToggleState.Off Then
customControl.controlColor = Color.Yellow
ElseIf toggleState = Windows.Automation.ToggleState.Indeterminate Then
customControl.controlColor = Color.Green
End If
customControl.Refresh()
End Sub))
End Sub
備註
控制項必須依此順序迴圈流覽其切換狀態: On 、 Off 和 (如果支援) Indeterminate 。