This topic has not yet been rated - Rate this topic

AccessibleObject.Select Method

Modifies the selection or moves the keyboard focus of the accessible object.

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)
[SecurityPermissionAttribute(SecurityAction.Demand, Flags = SecurityPermissionFlag.UnmanagedCode)]
public virtual void Select(
	AccessibleSelection flags
)

Parameters

flags
Type: System.Windows.Forms.AccessibleSelection

One of the AccessibleSelection values.

ExceptionCondition
COMException

The selection cannot be performed.

Applications can use this method to perform complex selection operations.

The following describes which AccessibleSelection values to specify when calling Select to perform complex selection operations.

Operation

Flag Combination

To simulate a click

AccessibleSelection.TakeFocus OR AccessibleSelection.TakeSelection

NoteNote

This combination will not select the desired control if called from within your own application. It will have the desired effect, however, if called from an external application.

To select a target item by simulating CTRL + click

AccessibleSelection.TakeFocus OR AccessibleSelection.AddSelection

To cancel selection of a target item by simulating CTRL + click

AccessibleSelection.TakeFocus OR AccessibleSelection.RemoveSelection

To simulate SHIFT + click

AccessibleSelection.TakeFocus OR AccessibleSelection.ExtendSelection

To select a range of objects and put focus on the last object

Specify AccessibleSelection.TakeFocus on the starting object to set the selection anchor. Then call Select again and specify AccessibleSelection.TakeFocus OR AccessibleSelection.ExtendSelection on the last object.

To deselect all objects

Specify AccessibleSelection.TakeSelection on any object. This flag deselects all selected objects except the one just selected. Then call Select again and specify AccessibleSelection.RemoveSelection on the same object.

Notes to Inheritors

All objects that can be selected or receive the keyboard focus must support this method.

The following example demonstrates the creation of an accessibility-aware chart control, using the AccessibleObject and Control.ControlAccessibleObject classes to expose accessible information. The control plots two curves along with a legend. The ChartControlAccessibleObject class, which derives from ControlAccessibleObject, is used in the CreateAccessibilityInstance method to provide custom accessible information for the chart control. Since the chart legend is not an actual Control -based control, but instead is drawn by the chart control, it does not have any built-in accessible information. Because of this, the ChartControlAccessibleObject class overrides the GetChild method to return the CurveLegendAccessibleObject that represents accessible information for each part of the legend. When an accessible-aware application uses this control, the control can provide the necessary accessible information.

This code demonstrates shows overriding the Select method. See the AccessibleObject class overview for the complete code example.

// Inner class CurveLegendAccessibleObject represents accessible information  
// associated with the CurveLegend object. 
public class CurveLegendAccessibleObject : AccessibleObject
{
    private CurveLegend curveLegend;

    public CurveLegendAccessibleObject(CurveLegend curveLegend) : base() 
    {
        this.curveLegend = curveLegend;                    
    }                

    // Private property that helps get the reference to the parent ChartControl. 
    private ChartControlAccessibleObject ChartControl
    {   
        get {
            return Parent as ChartControlAccessibleObject;
        }
    }

    // Internal helper function that returns the ID for this CurveLegend. 
    internal int ID
    {
        get {
            for(int i = 0; i < ChartControl.GetChildCount(); i++) {
                if (ChartControl.GetChild(i) == this) {
                    return i;
                }
            }
            return -1;
        }
    }

    // Gets the Bounds for the CurveLegend. This is used by accessibility programs. 
    public override Rectangle Bounds
    {
        get {                        
            // The bounds is in screen coordinates.
            Point loc = curveLegend.Location;
            return new Rectangle(curveLegend.chart.PointToScreen(loc), curveLegend.Size);
        }
    }

    // Gets or sets the Name for the CurveLegend. This is used by accessibility programs. 
    public override string Name
    {
        get {
            return curveLegend.Name;
        }
        set {
            curveLegend.Name = value;                        
        }
    }

    // Gets the Curve Legend Parent's Accessible object. 
    // This is used by accessibility programs. 
    public override AccessibleObject Parent
    {
        get {
            return curveLegend.chart.AccessibilityObject;
        }
    }

    // Gets the role for the CurveLegend. This is used by accessibility programs. 
    public override AccessibleRole Role 
    {
        get {
            return AccessibleRole.StaticText;
        }
    }

    // Gets the state based on the selection for the CurveLegend.  
    // This is used by accessibility programs. 
    public override AccessibleStates State 
    {
        get {
            AccessibleStates state = AccessibleStates.Selectable;
            if (curveLegend.Selected) 
            {
                state |= AccessibleStates.Selected;
            }
            return state;
        }
    }

    // Navigates through siblings of this CurveLegend. This is used by accessibility programs. 
    public override AccessibleObject Navigate(AccessibleNavigation navdir) 
    {
        // Uses the internal NavigateFromChild helper function that exists 
        // on ChartControlAccessibleObject. 
        return ChartControl.NavigateFromChild(this, navdir);
    }

    // Selects or unselects this CurveLegend. This is used by accessibility programs. 
    public override void Select(AccessibleSelection selection) 
    {
        // Uses the internal SelectChild helper function that exists 
        // on ChartControlAccessibleObject.
        ChartControl.SelectChild(this, selection);
    }
}

.NET Framework

Supported in: 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows Phone 8.1, Windows Phone 8, 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.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.