AccessibleObject.Navigate(AccessibleNavigation) 方法

定義

可巡覽到另一個可存取物件。

C#
public virtual System.Windows.Forms.AccessibleObject Navigate (System.Windows.Forms.AccessibleNavigation navdir);
C#
public virtual System.Windows.Forms.AccessibleObject? Navigate (System.Windows.Forms.AccessibleNavigation navdir);

參數

navdir
AccessibleNavigation

其中一個 AccessibleNavigation 值。

傳回

AccessibleObject

AccessibleObject,代表其中一個 AccessibleNavigation 值。

例外狀況

巡覽的嘗試失敗。

範例

下列範例示範如何使用 AccessibleObjectControl.ControlAccessibleObject 類別來公開無障礙資訊,來建立協助工具感知圖表控制項。 控制項會繪製兩個曲線以及圖例。 ChartControlAccessibleObject衍生自 ControlAccessibleObject 的 類別會用於 方法中 CreateAccessibilityInstance ,以提供圖表控制項的自訂可存取訊號。 由於圖表圖例不是實際的 Control 控制項,而是由圖表控制項繪製,因此它沒有任何內建的可存取訊號。 因此,類別 ChartControlAccessibleObjectGetChild 覆寫 方法,以傳回 CurveLegendAccessibleObject ,代表圖例每個部分的可存取訊號。 當可存取感知應用程式使用此控制項時,控制項可以提供必要的可存取訊號。

此程式碼示範如何覆寫 Navigate 方法。 AccessibleObject如需完整的程式碼範例,請參閱類別概觀。

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

備註

空間和邏輯導覽一律受限於容器內的使用者介面元素。 透過空間流覽,用戶端只能巡覽至起始物件的同層級。 根據與邏輯導覽搭配使用的導覽旗標,用戶端可以巡覽至子系或起始物件的同層級。 這個方法不會變更選取範圍或焦點。 若要變更焦點或選取物件,請使用 Select 。 方法 Navigate 只會擷取具有已定義螢幕位置的使用者介面元素。

給繼承者的注意事項

所有視覺物件都必須支援這個方法。 如果物件具有狀態 Invisible ,則流覽至這個隱藏物件可能會失敗。 某些系統定義的介面元素,例如功能表、功能表項目和快顯功能表,都允許流覽至看不到的物件。 不過,其他系統定義的使用者介面元素不支援此專案。 可能的話,伺服器應該支援巡覽至看不到的物件,但不需要此支援,而且用戶端不應該預期它。

適用於

產品 版本
.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