다음을 통해 공유


IToggleProvider.Toggle 메서드

정의

컨트롤의 설정/해제 상태를 순환합니다.

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

설명

컨트롤은 토글 상태를 OnOffIndeterminate순서대로 순환해야 합니다.

적용 대상

추가 정보