Export (0) Print
Expand All

AccessibleObject.Select Method

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

[Visual Basic]
Public Overridable Sub Select( _
   ByVal flags As AccessibleSelection _
)
[C#]
public virtual void Select(
 AccessibleSelection flags
);
[C++]
public: virtual void Select(
 AccessibleSelection flags
);
[JScript]
public function Select(
   flags : AccessibleSelection
);

Parameters

flags
One of the AccessibleSelection values.

Exceptions

Exception Type Condition
COMException The selection cannot be performed.

Remarks

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
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.

Example

[Visual Basic, C#, C++] 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 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.

[Visual Basic, C#, C++] This code demonstrates shows overriding the Select method. See the AccessibleObject class overview for the complete code example.

[Visual Basic] 
' Inner class CurveLegendAccessibleObject represents accessible information 
' associated with the CurveLegend object.
Public Class CurveLegendAccessibleObject
    Inherits AccessibleObject

    Private curveLegend As CurveLegend
    
    Public Sub New(curveLegend As CurveLegend)
        Me.curveLegend = curveLegend
    End Sub 'New
    
    ' Private property that helps get the reference to the parent ChartControl.                
    Private ReadOnly Property ChartControl() As ChartControlAccessibleObject
        Get
            Return CType(Parent, ChartControlAccessibleObject)
        End Get
    End Property

    ' Friend helper function that returns the ID for this CurveLegend.                
    Friend ReadOnly Property ID() As Integer
        Get
            Dim i As Integer
            For i = 0 To (ChartControl.GetChildCount()) - 1
                If ChartControl.GetChild(i) Is Me Then
                    Return i
                End If
            Next i
            Return - 1
        End Get
    End Property
    
    ' Gets the Bounds for the CurveLegend. This is used by accessibility programs.
    Public Overrides ReadOnly Property Bounds() As Rectangle
        Get
            ' The bounds is in screen coordinates.
            Dim loc As Point = curveLegend.Location
            Return New Rectangle(curveLegend.chart.PointToScreen(loc), curveLegend.Size)
        End Get
    End Property

    ' Gets or sets the Name for the CurveLegend. This is used by accessibility programs.                
    Public Overrides Property Name() As String
        Get
            Return curveLegend.Name
        End Get
        Set
            curveLegend.Name = value
        End Set
    End Property
    
    ' Gets the Curve Legend Parent's Accessible object.
    ' This is used by accessibility programs.                
    Public Overrides ReadOnly Property Parent() As AccessibleObject
        Get
            Return curveLegend.chart.AccessibilityObject
        End Get
    End Property
    
    ' Gets the role for the CurveLegend. This is used by accessibility programs.                
    Public Overrides ReadOnly Property Role() As AccessibleRole
        Get
            Return System.Windows.Forms.AccessibleRole.StaticText
        End Get
    End Property

    ' Gets the state based on the selection for the CurveLegend. 
    ' This is used by accessibility programs.                
    Public Overrides ReadOnly Property State() As AccessibleStates
        Get
            Dim stateTemp As AccessibleStates = AccessibleStates.Selectable
            If curveLegend.Selected Then
                stateTemp = stateTemp Or AccessibleStates.Selected
            End If
            Return stateTemp
        End Get
    End Property
    
    ' Navigates through siblings of this CurveLegend. This is used by accessibility programs.                
    Public Overrides Function Navigate(navdir As AccessibleNavigation) As AccessibleObject
        ' Use the Friend NavigateFromChild helper function that exists
        ' on ChartControlAccessibleObject.
        Return ChartControl.NavigateFromChild(Me, navdir)
    End Function
    
    ' Selects or unselects this CurveLegend. This is used by accessibility programs.
    Public Overrides Sub [Select](selection As AccessibleSelection)

        ' Use the internal SelectChild helper function that exists
        ' on ChartControlAccessibleObject.
        ChartControl.SelectChild(Me, selection)
    End Sub

End Class 'CurveLegendAccessibleObject

[C#] 
// 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);
    }
}

[C++] 
// Inner class CurveLegendAccessibleObject represents accessible information
// associated with the CurveLegend object.
   public:
__gc class CurveLegendAccessibleObject : public AccessibleObject {
private:
   CurveLegend*  curveLegend;

public:
   CurveLegendAccessibleObject(CurveLegend* curveLegend) : AccessibleObject() {
      this->curveLegend = curveLegend;
   }

   // Private property that helps get the reference to the parent ChartControl.
private:
   __property ChartControlAccessibleObject* get_ChartControl() {
      return dynamic_cast<ChartControlAccessibleObject*>(Parent);
   }


   // Internal helper function that returns the ID for this CurveLegend.
public private:
   __property int get_ID() {
      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:
   __property Rectangle get_Bounds() {
      // The bounds is in screen coordinates.
      Point loc = curveLegend->Location;
      return Rectangle(curveLegend->chart->PointToScreen(loc), curveLegend->Size);
   }

   // Gets or sets the Name for the CurveLegend. This is used by accessibility programs.
   __property String* get_Name() {
      return curveLegend->Name;
   }
   __property void set_Name(String* value) {
      curveLegend->Name = value;
   }

   // Gets the Curve Legend Parent's Accessible object.
   // This is used by accessibility programs.
   __property AccessibleObject* get_Parent() {
      return curveLegend->chart->AccessibilityObject;
   }

   // Gets the role for the CurveLegend. This is used by accessibility programs.
   __property System::Windows::Forms::AccessibleRole get_Role() {
      return AccessibleRole::StaticText;
   }

   // Gets the state based on the selection for the CurveLegend.
   // This is used by accessibility programs.
   __property AccessibleStates get_State() {
      AccessibleStates state = AccessibleStates::Selectable;
      if (curveLegend->Selected) {
         state = static_cast<AccessibleStates>( state | AccessibleStates::Selected );
      }
      return state;
   }

   // Navigates through siblings of this CurveLegend. This is used by accessibility programs.
   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.
   void Select(AccessibleSelection selection) {
      // Uses the internal SelectChild helper function that exists
      // on ChartControlAccessibleObject.
      ChartControl->SelectChild(this, selection);
   }
}; // class CurveLgendAccessibleObject

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

AccessibleObject Class | AccessibleObject Members | System.Windows.Forms Namespace

Show:
© 2014 Microsoft