AccessibleObject.Select(AccessibleSelection) Méthode

Définition

Modifie la sélection ou déplace le focus clavier de l'objet accessible.

public:
 virtual void Select(System::Windows::Forms::AccessibleSelection flags);
public virtual void Select (System.Windows.Forms.AccessibleSelection flags);
abstract member Select : System.Windows.Forms.AccessibleSelection -> unit
override this.Select : System.Windows.Forms.AccessibleSelection -> unit
Public Overridable Sub Select (flags As AccessibleSelection)

Paramètres

flags
AccessibleSelection

Une des valeurs de l'objet AccessibleSelection.

Exceptions

La sélection ne peut pas être effectuée.

Exemples

L’exemple suivant illustre la création d’un contrôle de graphique prenant en compte l’accessibilité, en utilisant les classes et Control.ControlAccessibleObject les AccessibleObject classes pour exposer des informations accessibles. Le contrôle trace deux courbes avec une légende. La ChartControlAccessibleObject classe, qui dérive de ControlAccessibleObject, est utilisée dans la CreateAccessibilityInstance méthode pour fournir des informations accessibles personnalisées pour le contrôle de graphique. Étant donné que la légende du graphique n’est pas un contrôle réel Control , mais qu’elle est dessinée par le contrôle de graphique, elle n’a pas d’informations accessibles intégrées. En raison de cela, la ChartControlAccessibleObject classe remplace la GetChild méthode pour renvoyer les CurveLegendAccessibleObject informations accessibles pour chaque partie de la légende. Lorsqu’une application prenant en charge l’accès utilise ce contrôle, le contrôle peut fournir les informations accessibles nécessaires.

Ce code illustre la substitution de la Select méthode. Consultez la vue d’ensemble de la classe pour l’exemple AccessibleObject de code complet.

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

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


   private:

      property ChartControlAccessibleObject^ ChartControl 
      {

         // Private property that helps get the reference to the parent ChartControl.
         ChartControlAccessibleObject^ get()
         {
            return dynamic_cast<ChartControlAccessibleObject^>(Parent);
         }

      }

   internal:

      property int ID 
      {

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

            }
            return  -1;
         }

      }

   public:

      property Rectangle Bounds 
      {

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

      }

      property String^ Name 
      {

         // Gets or sets the Name for the CurveLegend. This is used by accessibility programs.
         virtual String^ get() override
         {
            return curveLegend->Name;
         }

         virtual void set( String^ value ) override
         {
            curveLegend->Name = value;
         }

      }

      property AccessibleObject^ Parent 
      {

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

      }

      property System::Windows::Forms::AccessibleRole Role 
      {

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

      }

      property AccessibleStates State 
      {

         // Gets the state based on the selection for the CurveLegend.
         // This is used by accessibility programs.
         virtual AccessibleStates get() override
         {
            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.
      virtual AccessibleObject^ Navigate( AccessibleNavigation navdir ) override
      {
         
         // 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.
      virtual void Select( AccessibleSelection selection ) override
      {
         
         // Uses the internal SelectChild helper function that exists
         // on ChartControlAccessibleObject.
         ChartControl->SelectChild( this, selection );
      }

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

Remarques

Les applications peuvent utiliser cette méthode pour effectuer des opérations de sélection complexes.

L’exemple suivant décrit les AccessibleSelection valeurs à spécifier lors de l’appel Select pour effectuer des opérations de sélection complexes.

Opération Combinaison d’indicateurs
Pour simuler un clic AccessibleSelection.TakeFocusOR AccessibleSelection.TakeSelection Remarque : cette combinaison ne sélectionne pas le contrôle souhaité si elle est appelée dans votre propre application. Toutefois, il aura l’effet souhaité, s’il est appelé à partir d’une application externe.
Pour sélectionner un élément cible en simulant ctrl + clic AccessibleSelection.TakeFocus OR AccessibleSelection.AddSelection
Pour annuler la sélection d’un élément cible en simulant ctrl + clic AccessibleSelection.TakeFocus OR AccessibleSelection.RemoveSelection
Pour simuler MAJ + clic AccessibleSelection.TakeFocus OR AccessibleSelection.ExtendSelection
Pour sélectionner une plage d’objets et mettre le focus sur le dernier objet Spécifiez AccessibleSelection.TakeFocus sur l’objet de départ pour définir l’ancre de sélection. Ensuite, appelez Select à nouveau et spécifiez-le AccessibleSelection.TakeFocus OR AccessibleSelection.ExtendSelection sur le dernier objet.
Pour désélectionner tous les objets Spécifiez AccessibleSelection.TakeSelection sur n’importe quel objet. Cet indicateur désélectionne tous les objets sélectionnés à l’exception de celui qui vient d’être sélectionné. Ensuite, appelez Select à nouveau et spécifiez AccessibleSelection.RemoveSelection sur le même objet.

Notes pour les héritiers

Tous les objets pouvant être sélectionnés ou reçus le focus clavier doivent prendre en charge cette méthode.

S’applique à