AccessibleObject.Parent Proprietà

Definizione

Ottiene l'oggetto padre di un oggetto accessibile.

C#
public virtual System.Windows.Forms.AccessibleObject Parent { get; }
C#
public virtual System.Windows.Forms.AccessibleObject? Parent { get; }

Valore della proprietà

AccessibleObject

Oggetto AccessibleObject che rappresenta l'elemento padre di un oggetto accessibile o null se non c'è alcun oggetto padre.

Esempio

Nell'esempio seguente viene illustrata la creazione di un controllo grafico compatibile con l'accessibilità, usando le AccessibleObject classi e Control.ControlAccessibleObject per esporre informazioni accessibili. Il controllo traccia due curve insieme a una legenda. La ChartControlAccessibleObject classe , che deriva da ControlAccessibleObject, viene utilizzata nel CreateAccessibilityInstance metodo per fornire informazioni personalizzate accessibili per il controllo grafico. Poiché la legenda del grafico non è un controllo effettivo Control basato su , ma viene invece disegnato dal controllo grafico, non dispone di informazioni accessibili predefinite. Per questo motivo, la ChartControlAccessibleObject classe esegue l'override del GetChild metodo per restituire l'oggetto CurveLegendAccessibleObject che rappresenta informazioni accessibili per ogni parte della legenda. Quando un'applicazione con riconoscimento dell'accesso usa questo controllo, il controllo può fornire le informazioni accessibili necessarie.

Questo estratto di codice illustra l'override della Parent proprietà . Vedere la panoramica della AccessibleObject classe per l'esempio di codice completo.

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

Note per gli eredi

Tutti gli oggetti devono supportare questa proprietà.

Si applica a

Prodotto Versioni
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8
Windows Desktop 3.0, 3.1, 5, 6, 7

Vedi anche