Control.ControlAccessibleObject 類別

定義

提供可供協助工具應用程式使用之控制項的相關資訊。

public: ref class Control::ControlAccessibleObject : System::Windows::Forms::AccessibleObject
[System.Runtime.InteropServices.ComVisible(true)]
public class Control.ControlAccessibleObject : System.Windows.Forms.AccessibleObject
public class Control.ControlAccessibleObject : System.Windows.Forms.AccessibleObject
[<System.Runtime.InteropServices.ComVisible(true)>]
type Control.ControlAccessibleObject = class
    inherit AccessibleObject
type Control.ControlAccessibleObject = class
    inherit AccessibleObject
Public Class Control.ControlAccessibleObject
Inherits AccessibleObject
繼承
Control.ControlAccessibleObject
繼承
衍生
屬性

範例

下列程式碼範例會建立衍生自 類別的 CheckBox 核取方塊控制項,並針對要使用的衍生類別建立自訂 Control.ControlAccessibleObject 。 衍生類別 MyCheckBox 預設為 AppearanceButton ,因此會顯示為切換按鈕。 衍生 Control.ControlAccessibleObject 類別 MyCheckBoxControlAccessibleObject 會覆寫三個屬性,以考慮外觀的差異。

#using <Accessibility.dll>
#using <System.Drawing.dll>
#using <System.dll>
#using <System.Windows.Forms.dll>

using namespace System;
using namespace System::Windows::Forms;
using namespace System::Drawing;

namespace MyCustomControls
{
   public ref class MyCheckBox: public CheckBox
   {
   public:
      MyCheckBox()
      {
         // Make the check box appear like a toggle button.
         this->Appearance = ::Appearance::Button;

         // Center the text on the button.
         this->TextAlign = ContentAlignment::MiddleCenter;

         // Set the AccessibleDescription text.
         this->AccessibleDescription = "A toggle style button.";
      }

   protected:

      // Create an instance of the AccessibleObject
      // defined for the 'MyCheckBox' control
      virtual AccessibleObject^ CreateAccessibilityInstance() override;
   };

   // Accessible Object* for use with the 'MyCheckBox' control.
   private ref class MyCheckBoxAccessibleObject: public Control::ControlAccessibleObject
   {
   public:
      MyCheckBoxAccessibleObject( MyCheckBox^ owner )
         : ControlAccessibleObject( owner )
      {}

      property String^ DefaultAction 
      {
         virtual String^ get() override
         {
            // Return the DefaultAction based upon
            // the state of the control.
            if ( (dynamic_cast<MyCheckBox^>(Owner))->Checked )
            {
               return "Toggle button up";
            }
            else
            {
               return "Toggle button down";
            }
         }
      }

      property String^ Name 
      {
         virtual String^ get() override
         {
            // Return the Text property of the control
            // if the AccessibleName is 0.
            String^ name = Owner->AccessibleName;
            if ( name != nullptr )
            {
               return name;
            }

            return (dynamic_cast<MyCheckBox^>(Owner))->Text;
         }

         virtual void set( String^ value ) override
         {
            ControlAccessibleObject::Name = value;
         }
      }

      property AccessibleRole Role 
      {
         virtual AccessibleRole get() override
         {
            // Since the check box appears like a button,
            // make the Role the same as a button.
            return AccessibleRole::PushButton;
         }
      }
   };

   AccessibleObject^ MyCheckBox::CreateAccessibilityInstance()
   {
      return gcnew MyCheckBoxAccessibleObject( this );
   }
}
using System;
using System.Windows.Forms;
using Accessibility;
using System.Drawing;

namespace MyCustomControls
{
   public class MyCheckBox : CheckBox
   {
      public MyCheckBox()
      {
         // Make the check box appear like a toggle button.
         this.Appearance = Appearance.Button;
         // Center the text on the button.
         this.TextAlign = ContentAlignment.MiddleCenter;
         // Set the AccessibleDescription text.
         this.AccessibleDescription = "A toggle style button.";
      }
      
      // Create an instance of the AccessibleObject 
      // defined for the 'MyCheckBox' control
      protected override AccessibleObject CreateAccessibilityInstance() 
      {
         return new MyCheckBoxAccessibleObject(this);
      }
   }

   // Accessible object for use with the 'MyCheckBox' control.
   internal class MyCheckBoxAccessibleObject : Control.ControlAccessibleObject 
   {
      public MyCheckBoxAccessibleObject(MyCheckBox owner) : base(owner) 
      {
      }
               
      public override string DefaultAction 
      {
         get
         {
            // Return the DefaultAction based upon 
            // the state of the control.
            if( ((MyCheckBox)Owner).Checked )
            {
               return "Toggle button up";
            }
            else
            {
               return "Toggle button down";
            }
         }
      }

      public override string Name 
      {
         get 
         {
            // Return the Text property of the control 
            // if the AccessibleName is null.
            string name = Owner.AccessibleName;
            if (name != null) 
            {
               return name;
            }
            return ((MyCheckBox)Owner).Text;
         }
         
         set
         {
            base.Name = value;
         }
      }            
               
      public override AccessibleRole Role 
      {
         get 
         {
            // Since the check box appears like a button,
            // make the Role the same as a button.
            return AccessibleRole.PushButton;
         }
      }
   }
}
Imports System.Windows.Forms
Imports Accessibility
Imports System.Drawing

Namespace MyCustomControls
   Public Class MyCheckBox
      Inherits CheckBox
      
      Public Sub New()
         ' Make the check box appear like a toggle button.
         Me.Appearance = Appearance.Button
         ' Center the text on the button.
         Me.TextAlign = ContentAlignment.MiddleCenter
      End Sub
      
      ' Create an instance of the AccessibleObject 
      ' defined for the 'MyCheckBox' control 
      Protected Overrides Function CreateAccessibilityInstance() _
        As AccessibleObject
         Return New MyCheckBoxAccessibleObject(Me)
      End Function
   End Class
    
   ' Accessible object for use with the 'MyCheckBox' control.
   Friend Class MyCheckBoxAccessibleObject
      Inherits Control.ControlAccessibleObject
      
      Public Sub New(owner As MyCheckBox)
         MyBase.New(owner)
      End Sub
      
      Public Overrides ReadOnly Property DefaultAction() As String
         Get
            ' Return the DefaultAction based upon 
            ' the state of the control. 
            If CType(Owner, MyCheckBox).Checked Then
               Return "Toggle button up"
            Else
               Return "Toggle button down"
            End If
         End Get
      End Property
      
      Public Overrides Property Name() As String
         Get
            ' Return the Text property of the control 
            ' if the AccessibleName is null. 
            Dim accessibleName As String = Owner.AccessibleName
            If (accessibleName IsNot Nothing) Then
               Return accessibleName
            End If
            Return CType(Owner, MyCheckBox).Text
         End Get

         Set
            MyBase.Name = value
         End Set
      End Property
      
      Public Overrides ReadOnly Property Role() As AccessibleRole
         Get
            ' Since the check box appears like a button,
            ' make the Role the same as a button. 
            Return AccessibleRole.PushButton
         End Get
      End Property
   End Class
End Namespace

備註

Windows Forms內建協助工具支援,並提供可讓您使用協助工具用戶端應用程式的應用程式相關資訊。 協助工具用戶端應用程式的範例包括:螢幕放大和檢閱者公用程式、語音輸入公用程式、螢幕鍵盤、替代輸入裝置,以及鍵盤增強公用程式。 有時候,您會想要提供協助工具用戶端應用程式的其他資訊。 提供這項額外資訊的方式有兩種。 若要為現有控制項提供有限的協助工具資訊,請設定控制項的 AccessibleNameAccessibleDescriptionAccessibleDefaultActionDescriptionAccessibleRole 屬性值,這會向協助工具用戶端應用程式回報。 或者,如果您需要將更多協助工具資訊包含在控制項中,您可以撰寫衍生自 或 Control.ControlAccessibleObject 類別的 AccessibleObject 專屬類別。 例如,如果您要撰寫不是衍生自通用控制項的控制項,或您需要控制項內的這類作業,例如點擊測試,您應該呼叫 方法來建立 Control.ControlAccessibleObject 控制項的 CreateAccessibilityInstance

注意

如果您覆寫 AccessibleObject.GetChild 方法,您也必須覆寫 AccessibleObject.GetChildCount 方法。 若要取得或設定 AccessibilityObject 屬性,您必須新增與 .NET Framework 一起安裝的元件參考 Accessibility

如需可存取物件的詳細資訊,請參閱Microsoft Active Accessibility

建構函式

Control.ControlAccessibleObject(Control)

初始化 Control.ControlAccessibleObject 類別的新執行個體。

屬性

Bounds

取得可存取物件的位置和大小。

(繼承來源 AccessibleObject)
DefaultAction

取得描述物件之預設動作的字串。 並非所有的物件都有預設動作。

Description

取得 Control.ControlAccessibleObject 的描述。

Handle

取得或設定可存取物件的控制代碼。

Help

取得物件的用途或物件使用方式的描述。

KeyboardShortcut

取得可存取物件的物件快速鍵或便捷鍵 (Access Key)。

Name

取得或設定可存取的物件名稱。

Owner

取得可存取物件的擁有人。

Parent

取得可存取之物件的父系。

Role

取得這個可存取之物件的角色。

State

取得這個可存取物件的狀態。

(繼承來源 AccessibleObject)
Value

取得或設定可存取物件的數值。

(繼承來源 AccessibleObject)

方法

CreateObjRef(Type)

建立包含所有相關資訊的物件,這些資訊是產生用來與遠端物件通訊的所需 Proxy。

(繼承來源 MarshalByRefObject)
DoDefaultAction()

執行與這個可存取物件相關的預設動作。

(繼承來源 AccessibleObject)
Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
GetChild(Int32)

擷取與指定索引相對應的可存取子系。

(繼承來源 AccessibleObject)
GetChildCount()

擷取屬於可存取物件的子系數目。

(繼承來源 AccessibleObject)
GetFocused()

擷取具有鍵盤焦點的物件。

(繼承來源 AccessibleObject)
GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetHelpTopic(String)

取得說明主題的識別項,以及與這個可存取物件相關之通往說明檔的路徑。

GetLifetimeService()
已淘汰.

擷取控制這個執行個體存留期 (Lifetime) 原則的目前存留期服務物件。

(繼承來源 MarshalByRefObject)
GetSelected()

擷取目前選取的子系。

(繼承來源 AccessibleObject)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
HitTest(Int32, Int32)

擷取位於指定螢幕座標的子物件。

(繼承來源 AccessibleObject)
InitializeLifetimeService()
已淘汰.

取得存留期服務物件,以控制這個執行個體的存留期原則。

(繼承來源 MarshalByRefObject)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
MemberwiseClone(Boolean)

建立目前 MarshalByRefObject 物件的淺層複本。

(繼承來源 MarshalByRefObject)
Navigate(AccessibleNavigation)

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

(繼承來源 AccessibleObject)
NotifyClients(AccessibleEvents)

將指定的 AccessibleEvents 告知可及性用戶端應用程式。

NotifyClients(AccessibleEvents, Int32)

將指定子控制項的指定 AccessibleEvents 告知協助工具用戶端應用程式。

NotifyClients(AccessibleEvents, Int32, Int32)

將指定子控制項的指定 AccessibleEvents 告知可及性用戶端應用程式,提供 AccessibleObject 的識別。

RaiseAutomationNotification(AutomationNotificationKind, AutomationNotificationProcessing, String)

引發使用者介面自動化通知事件。

(繼承來源 AccessibleObject)
RaiseLiveRegionChanged()

引發 LiveRegionChanged 使用者介面自動化事件。

RaiseLiveRegionChanged()

引發 LiveRegionChanged 使用者介面自動化事件。

(繼承來源 AccessibleObject)
Select(AccessibleSelection)

修改選取或者移動可存取物件的鍵盤焦點。

(繼承來源 AccessibleObject)
ToString()

傳回代表目前物件的字串。

UseStdAccessibleObjects(IntPtr)

根據物件的控制代碼,將物件與 AccessibleObject 的執行個體產生關聯。

(繼承來源 AccessibleObject)
UseStdAccessibleObjects(IntPtr, Int32)

根據物件的控制代碼和物件 ID,將物件與 AccessibleObject 的執行個體產生關聯。

(繼承來源 AccessibleObject)

明確介面實作

IAccessible.accChildCount

取得屬於這個物件的子介面數目。 如需這個成員的說明,請參閱 accChildCount

(繼承來源 AccessibleObject)
IAccessible.accDoDefaultAction(Object)

執行指定物件的預設動作。 並非所有的物件都有預設動作。 如需這個成員的說明,請參閱 accDoDefaultAction(Object)

(繼承來源 AccessibleObject)
IAccessible.accFocus

取得具有鍵盤焦點的物件。 如需這個成員的說明,請參閱 accFocus

(繼承來源 AccessibleObject)
IAccessible.accHitTest(Int32, Int32)

取得位於指定螢幕座標的子物件。 如需這個成員的說明,請參閱 accHitTest(Int32, Int32)

(繼承來源 AccessibleObject)
IAccessible.accLocation(Int32, Int32, Int32, Int32, Object)

取得物件的目前螢幕位置。 如需這個成員的說明,請參閱 accLocation(Int32, Int32, Int32, Int32, Object)

(繼承來源 AccessibleObject)
IAccessible.accNavigate(Int32, Object)

巡覽至相對於目前物件的可存取物件。 如需這個成員的說明,請參閱 accNavigate(Int32, Object)

(繼承來源 AccessibleObject)
IAccessible.accParent

取得這個物件的可存取父物件。 如需這個成員的說明,請參閱 accParent

(繼承來源 AccessibleObject)
IAccessible.accSelect(Int32, Object)

修改選取或者移動可存取物件的鍵盤焦點。 如需這個成員的說明,請參閱 accSelect(Int32, Object)

(繼承來源 AccessibleObject)
IAccessible.accSelection

取得可存取物件的選定子物件。 如需這個成員的說明,請參閱 accSelection

(繼承來源 AccessibleObject)
IReflect.GetField(String, BindingFlags)

取得對應到指定欄位和繫結旗標的 FieldInfo 物件。 如需這個成員的說明,請參閱 GetField(String, BindingFlags)

(繼承來源 AccessibleObject)
IReflect.GetFields(BindingFlags)

取得對應到目前類別的所有欄位之 FieldInfo 物件陣列。 如需這個成員的說明,請參閱 GetFields(BindingFlags)

(繼承來源 AccessibleObject)
IReflect.GetMember(String, BindingFlags)

取得 MemberInfo 物件陣列,其會對應到所有公用成員或所有符合指定名稱的成員。 如需這個成員的說明,請參閱 GetMember(String, BindingFlags)

(繼承來源 AccessibleObject)
IReflect.GetMembers(BindingFlags)

取得 MemberInfo 物件陣列,其會對應到所有公用成員或目前類別的所有成員。 如需這個成員的說明,請參閱 GetMembers(BindingFlags)

(繼承來源 AccessibleObject)
IReflect.GetMethod(String, BindingFlags)

取得 MethodInfo 物件,其會對應到指定搜尋條件約束下的指定方法。 如需這個成員的說明,請參閱 GetMethod(String, BindingFlags)

(繼承來源 AccessibleObject)
IReflect.GetMethod(String, BindingFlags, Binder, Type[], ParameterModifier[])

使用 Type 陣列從多載方法中選擇,取得對應到指定方法的 MethodInfo 物件。 如需這個成員的說明,請參閱 GetMethod(String, BindingFlags, Binder, Type[], ParameterModifier[])

(繼承來源 AccessibleObject)
IReflect.GetMethods(BindingFlags)

取得包含所有公用方法或目前類別的所有方法的 MethodInfo 物件陣列。 如需這個成員的說明,請參閱 GetMethods(BindingFlags)

(繼承來源 AccessibleObject)
IReflect.GetProperties(BindingFlags)

取得 PropertyInfo 物件陣列,其會對應到所有公用屬性或目前類別的所有屬性。 如需這個成員的說明,請參閱 GetProperties(BindingFlags)

(繼承來源 AccessibleObject)
IReflect.GetProperty(String, BindingFlags)

取得 PropertyInfo 物件,其會對應到指定搜尋條件約束下的指定屬性。 如需這個成員的說明,請參閱 GetProperty(String, BindingFlags)

(繼承來源 AccessibleObject)
IReflect.GetProperty(String, BindingFlags, Binder, Type, Type[], ParameterModifier[])

取得 PropertyInfo 物件,其會對應到具有指定搜尋條件約束的指定屬性。 如需這個成員的說明,請參閱 GetProperty(String, BindingFlags, Binder, Type, Type[], ParameterModifier[])

(繼承來源 AccessibleObject)
IReflect.InvokeMember(String, BindingFlags, Binder, Object, Object[], ParameterModifier[], CultureInfo, String[])

叫用指定成員。 如需這個成員的說明,請參閱 InvokeMember(String, BindingFlags, Binder, Object, Object[], ParameterModifier[], CultureInfo, String[])

(繼承來源 AccessibleObject)
IReflect.UnderlyingSystemType

取得表示 IReflect 物件的基礎型別。 如需這個成員的說明,請參閱 UnderlyingSystemType

(繼承來源 AccessibleObject)

適用於

另請參閱