Export (0) Print
Expand All

IToggleProvider.Toggle Method

Cycles through the toggle states of a control.

Namespace:  System.Windows.Automation.Provider
Assembly:  UIAutomationProvider (in UIAutomationProvider.dll)

void Toggle()

A control must cycle through its toggle states in this order: On, Off, and (if supported) Indeterminate.

The following example shows one possible implementation of this method for a custom control that can be toggled.

/// <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();
    }));
}

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft