Control.CreateAccessibilityInstance 方法

定義

為控制項建立新的協助工具物件。Creates a new accessibility object for the control.

protected:
 virtual System::Windows::Forms::AccessibleObject ^ CreateAccessibilityInstance();
protected virtual System.Windows.Forms.AccessibleObject CreateAccessibilityInstance ();
abstract member CreateAccessibilityInstance : unit -> System.Windows.Forms.AccessibleObject
override this.CreateAccessibilityInstance : unit -> System.Windows.Forms.AccessibleObject
Protected Overridable Function CreateAccessibilityInstance () As AccessibleObject

傳回

控制項新的 AccessibleObjectA new AccessibleObject for the control.

範例

下列程式碼範例示範如何建立可感知存取範圍的圖表控制項,使用 AccessibleObjectControl.ControlAccessibleObject 類別來公開可存取的資訊。The following code 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. 衍生自 ControlAccessibleObjectChartControlAccessibleObject 類別,會用於 CreateAccessibilityInstance 方法中,以便為 chart 控制項提供自訂的可存取訊號。The ChartControlAccessibleObject class, which derives from ControlAccessibleObject, is used in the CreateAccessibilityInstance method to provide custom accessible information for the chart control. 由於圖表圖例不是實際的 Control 型控制項,而是由 chart 控制項繪製,因此不會有任何內建的可存取訊號。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. 因此,ChartControlAccessibleObject 類別會覆寫 GetChild 方法,以傳回代表圖例每個部分之可存取訊號的 CurveLegendAccessibleObjectBecause 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.

這段程式碼摘錄會示範如何覆寫 CreateAccessibilityInstance 方法。This code excerpt demonstrates overriding the CreateAccessibilityInstance method. 如需完整的程式碼範例,請參閱 AccessibleObject 類別總覽。See the AccessibleObject class overview for the complete code example.

protected:
   // Overridden to return the custom AccessibleObject
   // for the entire chart.
   virtual AccessibleObject^ CreateAccessibilityInstance() override
   {
      return gcnew ChartControlAccessibleObject( this );
   }
// Overridden to return the custom AccessibleObject 
// for the entire chart.
protected override AccessibleObject CreateAccessibilityInstance() 
{            
    return new ChartControlAccessibleObject(this);
}
' Overridden to return the custom AccessibleObject 
' for the entire chart.
Protected Overrides Function CreateAccessibilityInstance() As AccessibleObject
    Return New ChartControlAccessibleObject(Me)
End Function 

備註

如果沒有明確呼叫 CreateAccessibilityInstance 方法,將會在參考 AccessibilityObject 屬性時呼叫該方法。If you do not explicitly call the CreateAccessibilityInstance method, it will be called when the AccessibilityObject property is referenced.

注意

若要取得或設定 AccessibilityObject 屬性,您必須將參考加入與 .NET Framework.NET Framework 一起安裝的 Accessibility 元件。To get or set the AccessibilityObject property, you must add a reference to the Accessibility assembly installed with the .NET Framework.NET Framework.

給繼承者的注意事項

在衍生類別中覆寫 CreateAccessibilityInstance() 時,請勿呼叫基類的 CreateAccessibilityInstance() 方法。When overriding CreateAccessibilityInstance() in a derived class, do not call the base class's CreateAccessibilityInstance() method.

適用於

另請參閱