AccessibleObject.Name Propriété

Définition

Obtient ou définit le nom de l'objet.Gets or sets the object name.

public:
 virtual property System::String ^ Name { System::String ^ get(); void set(System::String ^ value); };
public virtual string Name { get; set; }
member this.Name : string with get, set
Public Overridable Property Name As String

Valeur de propriété

Nom de l'objet, ou null si la propriété n'a pas été définie.The object name, or null if the property has not been set.

Exceptions

Le nom du contrôle ne peut pas être récupéré ou défini.The name of the control cannot be retrieved or set.

Exemples

L’exemple suivant illustre la création d’un contrôle de graphique prenant en charge l’accessibilité, à l’aide des classes AccessibleObject et Control.ControlAccessibleObject pour exposer des informations accessibles.The following example demonstrates the creation of an accessibility-aware chart control, using the AccessibleObject and Control.ControlAccessibleObject classes to expose accessible information. Le contrôle trace deux courbes avec une légende.The control plots two curves along with a legend. La classe ChartControlAccessibleObject, qui dérive de ControlAccessibleObject, est utilisée dans la méthode CreateAccessibilityInstance pour fournir des informations accessibles personnalisées pour le contrôle Chart.The ChartControlAccessibleObject class, which derives from ControlAccessibleObject, is used in the CreateAccessibilityInstance method to provide custom accessible information for the chart control. Étant donné que la légende du graphique n’est pas un contrôle réel basé sur Control, mais qu’elle est dessinée par le contrôle Chart, elle n’a pas d’informations accessibles intégrées.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. Pour cette raison, la classe ChartControlAccessibleObject remplace la méthode GetChild pour retourner le CurveLegendAccessibleObject qui représente des informations accessibles pour chaque partie de la légende.Because of this, the ChartControlAccessibleObject class overrides the GetChild method to return the CurveLegendAccessibleObject that represents accessible information for each part of the legend. Lorsqu’une application qui prend en charge l’accès utilise ce contrôle, le contrôle peut fournir les informations accessibles nécessaires.When an accessible-aware application uses this control, the control can provide the necessary accessible information.

Cet extrait de code illustre la substitution de la propriété Name.This code excerpt demonstrates overriding the Name property. Consultez la vue d’ensemble de la classe AccessibleObject pour obtenir un exemple de code complet.See the AccessibleObject class overview for the complete code example.

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

La propriété Name est une chaîne utilisée par les clients pour identifier, Rechercher ou annoncer un objet pour l’utilisateur.The Name property is a string used by clients to identify, find, or announce an object for the user. Pour accéder au nom d’un objet enfant, vous devez d’abord appeler GetChild avec l’index de l’enfant dont vous récupérez le nom.To access the name of a child object, you must first call GetChild with the index of the child whose name you are retrieving.

Notes pour les héritiers

Tous les objets doivent prendre en charge cette propriété.All objects should support this property. Le nom d’un objet doit être intuitif afin que les utilisateurs comprennent la signification ou l’objectif de l’objet.An object's name should be intuitive so that users understand the object's meaning or purpose. En outre, assurez-vous que la propriété Name est unique par rapport à tous les objets frères dans le parent.Also, ensure that the Name property is unique relative to any sibling objects in the parent. La navigation dans les tables présente des problèmes particulièrement difficiles pour certains utilisateurs.Navigation within tables presents especially difficult problems for some users. Par conséquent, les développeurs de serveurs doivent faire en sorte que les noms des cellules de tableau soient aussi descriptifs que possible.Therefore, server developers should make table cell names as descriptive as possible. Par exemple, vous pouvez créer un nom de cellule en combinant les noms de la ligne et de la colonne qu’il occupe, par exemple « a1 ».For example, you might create a cell name by combining the names of the row and column it occupies, such as "A1." Toutefois, il est généralement préférable d’utiliser des noms plus descriptifs, tels que « discussion, février ».However, it is generally better to use more descriptive names, such as "Karin, February." De nombreux objets, tels que les icônes, les menus, les cases à cocher, les zones de liste modifiable et d’autres contrôles, possèdent des étiquettes qui sont affichées aux utilisateurs.Many objects, such as icons, menus, check boxes, combo boxes, and other controls, have labels that are displayed to users. Toute étiquette affichée aux utilisateurs doit être utilisée pour la propriété Name de l’objet.Any label displayed to users should be used for the object's Name property. Pour plus d’informations, consultez la propriété Name.For more information, see the Name Property.

Si vous utilisez un texte de menu ou de bouton pour la propriété Name, supprimez les esperluettes (&) qui marquent les touches d’accès clavier.If you are using menu or button text for the Name property, strip out the ampersands (&) that mark the keyboard access keys.

S’applique à

Voir aussi