Control.ControlAccessibleObject 类

定义

提供关于可以供辅助功能应用程序使用的控件的信息。Provides information about a control that can be used by an accessibility application.

public: ref class Control::ControlAccessibleObject : System::Windows::Forms::AccessibleObject
[System.Runtime.InteropServices.ComVisible(true)]
public class Control.ControlAccessibleObject : System.Windows.Forms.AccessibleObject
type Control.ControlAccessibleObject = class
    inherit AccessibleObject
Public Class Control.ControlAccessibleObject
Inherits AccessibleObject
继承
Control.ControlAccessibleObject
派生
属性

示例

下面的代码示例创建一个从CheckBox类派生的复选框控件,并为派生类创建要使用的自定义。 Control.ControlAccessibleObjectThe following code example creates a check box control that derives from the CheckBox class and creates a custom Control.ControlAccessibleObject for the derived class to use. 派生类MyCheckBox Appearance的默认值为,因此它显示为一个切换按钮。ButtonThe derived class, MyCheckBox, has an Appearance of Button by default so it appears as a toggle button. Control.ControlAccessibleObject 派生MyCheckBoxControlAccessibleObject类重写了三个属性,以考虑外观上的差异。The derived Control.ControlAccessibleObject class, MyCheckBoxControlAccessibleObject, overrides three properties to account for the difference in appearance.

#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 窗体内置了辅助功能支持,并提供了有关应用程序的信息,使其能够使用具有辅助功能的客户端应用程序。Windows Forms has accessibility support built in, and provides information about your application that enables it to work with accessibility client applications. 辅助功能客户端应用程序的示例包括:屏幕弱视和审阅者实用程序、语音输入实用程序、屏幕键盘、备用输入设备和键盘增强实用程序。Examples of accessibility client applications are: screen enlarger and reviewer utilities, voice input utilities, on-screen keyboards, alternative input devices, and keyboard enhancement utilities. 有时,你将需要向具有辅助功能的客户端应用程序提供其他信息。Sometimes you will want to provide additional information to accessibility client applications. 提供此附加信息的方法有两种。There are two ways of providing this additional information. 若要为现有控件提供有限的辅助功能信息,请AccessibleName设置AccessibleDescription控件AccessibleDefaultActionDescription的、 AccessibleRole 、和属性值,这些值将报告给具有辅助功能的客户端应用程序。To provide limited accessibility information for existing controls, set the control's AccessibleName, AccessibleDescription, AccessibleDefaultActionDescription, and AccessibleRole property values, which will be reported to accessibility client applications. 或者,如果你需要将更多辅助功能信息包含在控件中,则可以编写自己的派生自或AccessibleObject Control.ControlAccessibleObject类的类。Alternatively, if you require more accessibility information to be included with your control, you can write your own class deriving from the AccessibleObject or Control.ControlAccessibleObject classes. 例如,如果您正在编写自己的控件,该控件不是从公共控件派生的,或者您需要在控件中进行命中测试,则应通过Control.ControlAccessibleObject CreateAccessibilityInstance调用方法为控件创建一个。For example, if you are writing your own control that is not derived from the common controls or you require such operations as hit testing within your control, you should create a Control.ControlAccessibleObject for your control by calling the CreateAccessibilityInstance method.

备注

如果重写AccessibleObject.GetChild方法,则还必须AccessibleObject.GetChildCount重写方法。If you override the AccessibleObject.GetChild method, you must also override the AccessibleObject.GetChildCount method. 若要获取或设置AccessibilityObject属性,必须添加对与 .NET Framework 一起安装Accessibility的程序集的引用。To get or set the AccessibilityObject property, you must add a reference to the Accessibility assembly installed with the .NET Framework.

有关辅助性对象的更多信息,请参见 MSDN Library 中的“Active Accessibility”部分。For more information about accessible objects, see the Active Accessibility section of the MSDN Library.

构造函数

Control.ControlAccessibleObject(Control)

初始化 Control.ControlAccessibleObject 类的新实例。Initializes a new instance of the Control.ControlAccessibleObject class.

属性

Bounds

获取辅助性对象的位置和大小。Gets the location and size of the accessible object.

(继承自 AccessibleObject)
DefaultAction

获取描述对象默认操作的字符串。Gets a string that describes the default action of the object. 并非所有对象都有默认操作。Not all objects have a default action.

Description

获取 Control.ControlAccessibleObject 的说明。Gets the description of the Control.ControlAccessibleObject.

Handle

获取或设置辅助性对象的句柄。Gets or sets the handle of the accessible object.

Help

获取有关对象的用途或用法的说明。Gets the description of what the object does or how the object is used.

KeyboardShortcut

获取辅助性对象的快捷键或访问键。Gets the object shortcut key or access key for an accessible object.

Name

获取或设置可访问对象名称。Gets or sets the accessible object name.

Owner

获取辅助性对象的所有者。Gets the owner of the accessible object.

Parent

获取辅助性对象的父级。Gets the parent of an accessible object.

Role

获取此辅助性对象的角色。Gets the role of this accessible object.

State

获取此辅助性对象的状态。Gets the state of this accessible object.

(继承自 AccessibleObject)
Value

获取或设置辅助性对象的值。Gets or sets the value of an accessible object.

(继承自 AccessibleObject)

方法

CreateObjRef(Type)

创建一个对象,该对象包含生成用于与远程对象进行通信的代理所需的全部相关信息。Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.

(继承自 MarshalByRefObject)
DoDefaultAction()

执行与该辅助性对象相关的默认操作。Performs the default action associated with this accessible object.

(继承自 AccessibleObject)
Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
GetChild(Int32)

检索与指定索引对应的可访问子级。Retrieves the accessible child corresponding to the specified index.

(继承自 AccessibleObject)
GetChildCount()

检索属于可访问对象的子级的个数。Retrieves the number of children belonging to an accessible object.

(继承自 AccessibleObject)
GetFocused()

检索具有键盘焦点的对象。Retrieves the object that has the keyboard focus.

(继承自 AccessibleObject)
GetHashCode()

作为默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetHelpTopic(String)

获取帮助主题标识符及与该辅助性对象相关的帮助文件的路径。Gets an identifier for a Help topic and the path to the Help file associated with this accessible object.

GetLifetimeService()

检索控制此实例的生存期策略的当前生存期服务对象。Retrieves the current lifetime service object that controls the lifetime policy for this instance.

(继承自 MarshalByRefObject)
GetSelected()

检索当前选定的子级。Retrieves the currently selected child.

(继承自 AccessibleObject)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
HitTest(Int32, Int32)

检索位于指定屏幕坐标的子对象。Retrieves the child object at the specified screen coordinates.

(继承自 AccessibleObject)
InitializeLifetimeService()

获取生存期服务对象来控制此实例的生存期策略。Obtains a lifetime service object to control the lifetime policy for this instance.

(继承自 MarshalByRefObject)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
MemberwiseClone(Boolean)

创建当前 MarshalByRefObject 对象的浅表副本。Creates a shallow copy of the current MarshalByRefObject object.

(继承自 MarshalByRefObject)
Navigate(AccessibleNavigation)

定位到另一个辅助性对象。Navigates to another accessible object.

(继承自 AccessibleObject)
NotifyClients(AccessibleEvents)

通知指定的 AccessibleEvents 的辅助功能客户端应用程序。Notifies accessibility client applications of the specified AccessibleEvents.

NotifyClients(AccessibleEvents, Int32)

就指定子控件的指定 AccessibleEvents 通知辅助功能客户端应用程序。Notifies the accessibility client applications of the specified AccessibleEvents for the specified child control.

NotifyClients(AccessibleEvents, Int32, Int32)

就指定的子控件的指定 AccessibleEvents 通知辅助功能客户端应用程序,给定 AccessibleObject 的标识。Notifies the accessibility client applications of the specified AccessibleEvents for the specified child control, giving the identification of the AccessibleObject.

RaiseAutomationNotification(AutomationNotificationKind, AutomationNotificationProcessing, String)

引发 UI 自动化通知事件。Raises the UI automation notification event.

(继承自 AccessibleObject)
RaiseLiveRegionChanged()

引发 LiveRegionChanged UI 自动化事件。Raises the LiveRegionChanged UI automation event.

Select(AccessibleSelection)

修改选择内容或移动辅助性对象的键盘焦点。Modifies the selection or moves the keyboard focus of the accessible object.

(继承自 AccessibleObject)
ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

UseStdAccessibleObjects(IntPtr)

根据对象的句柄,将一个对象与 AccessibleObject 的一个实例关联起来。Associates an object with an instance of an AccessibleObject based on the handle of the object.

(继承自 AccessibleObject)
UseStdAccessibleObjects(IntPtr, Int32)

根据对象的句柄和对象 ID,将一个对象与 AccessibleObject 的一个实例关联起来。Associates an object with an instance of an AccessibleObject based on the handle and the object id of the object.

(继承自 AccessibleObject)

显式界面实现

IAccessible.accChildCount

获取属于该对象的子接口的数量。Gets the number of child interfaces that belong to this object. 有关此成员的说明,请参见 accChildCountFor a description of this member, see accChildCount.

(继承自 AccessibleObject)
IAccessible.accDoDefaultAction(Object)

执行指定对象的默认操作。Performs the specified object's default action. 并非所有对象都有默认操作。Not all objects have a default action. 有关此成员的说明,请参见 accDoDefaultAction(Object)For a description of this member, see accDoDefaultAction(Object).

(继承自 AccessibleObject)
IAccessible.accFocus

获取具有键盘焦点的对象。Gets the object that has the keyboard focus. 有关此成员的说明,请参见 accFocusFor a description of this member, see accFocus.

(继承自 AccessibleObject)
IAccessible.accHitTest(Int32, Int32)

在指定的屏幕坐标位置获取子对象。Gets the child object at the specified screen coordinates. 有关此成员的说明,请参见 accHitTest(Int32, Int32)For a description of this member, see accHitTest(Int32, Int32).

(继承自 AccessibleObject)
IAccessible.accLocation(Int32, Int32, Int32, Int32, Object)

获取对象的当前屏幕位置。Gets the object's current screen location. 有关此成员的说明,请参见 accLocation(Int32, Int32, Int32, Int32, Object)For a description of this member, see accLocation(Int32, Int32, Int32, Int32, Object).

(继承自 AccessibleObject)
IAccessible.accNavigate(Int32, Object)

相对于当前对象定位到一个辅助性对象。Navigates to an accessible object relative to the current object. 有关此成员的说明,请参见 accNavigate(Int32, Object)For a description of this member, see accNavigate(Int32, Object).

(继承自 AccessibleObject)
IAccessible.accParent

获取该对象的父辅助性对象。Gets the parent accessible object of this object. 有关此成员的说明,请参见 accParentFor a description of this member, see accParent.

(继承自 AccessibleObject)
IAccessible.accSelect(Int32, Object)

修改选择内容或移动辅助性对象的键盘焦点。Modifies the selection or moves the keyboard focus of the accessible object. 有关此成员的说明,请参见 accSelect(Int32, Object)For a description of this member, see accSelect(Int32, Object).

(继承自 AccessibleObject)
IAccessible.accSelection

获取辅助性对象的选定子对象。Gets the selected child objects of an accessible object. 有关此成员的说明,请参见 accSelectionFor a description of this member, see accSelection.

(继承自 AccessibleObject)
IAccessible.get_accChild(Object)

检索指定的子对象。Retrieves a specified child object.

(继承自 AccessibleObject)
IAccessible.get_accDefaultAction(Object)

返回指示指定对象的默认操作的字符串。Returns a string that indicates the specified object's default action.

(继承自 AccessibleObject)
IAccessible.get_accDescription(Object)

返回描述指定辅助性对象的可视外观的字符串。Returns a string that describes the visual appearance of the specified accessible object.

(继承自 AccessibleObject)
IAccessible.get_accHelp(Object)

检索与指定辅助性对象相关联的 WinHelp 文件的完整路径。Retrieves the full path of the WinHelp file that is associated with the specified accessible object.

(继承自 AccessibleObject)
IAccessible.get_accHelpTopic(String, Object)

检索与指定对象相关联的 WinHelp 文件的完整路径以及该文件中指定主题的标识符。Retrieves the full path of a WinHelp file that is associated with the specified object along with the identifier of a specific topic in the file.

(继承自 AccessibleObject)
IAccessible.get_accKeyboardShortcut(Object)

检索指定对象的键盘快捷方式或访问密钥。Retrieves the specified object's keyboard shortcut or access key.

(继承自 AccessibleObject)
IAccessible.get_accName(Object)

检索指定对象的名称。Retrieves the name of the specified object.

(继承自 AccessibleObject)
IAccessible.get_accRole(Object)

检索描述指定对象的角色的信息。Retrieves information that describes the role of the specified object.

(继承自 AccessibleObject)
IAccessible.get_accState(Object)

检索指定辅助性对象的当前状态。Retrieves the current state of the specified accessible object.

(继承自 AccessibleObject)
IAccessible.get_accValue(Object)

检索指定辅助性对象的值。Retrieves the value of the specified accessible object. 并非所有对象都有值。Not all objects have a value.

(继承自 AccessibleObject)
IAccessible.set_accName(Object, String)

将新的可访问名称分配给指定的元素。Assigns a new accessible name to the specified element.

(继承自 AccessibleObject)
IAccessible.set_accValue(Object, String)

将新的值分配给指定的元素。Assigns a new value to the specified element.

(继承自 AccessibleObject)
IReflect.GetField(String, BindingFlags)

获取与指定字段和绑定标志对应的 FieldInfo 对象。Gets the FieldInfo object corresponding to the specified field and binding flag. 有关此成员的说明,请参见 GetField(String, BindingFlags)For a description of this member, see GetField(String, BindingFlags).

(继承自 AccessibleObject)
IReflect.GetFields(BindingFlags)

获取与当前类的所有字段对应的 FieldInfo 对象的数组。Gets an array of FieldInfo objects corresponding to all fields of the current class. 有关此成员的说明,请参见 GetFields(BindingFlags)For a description of this member, see GetFields(BindingFlags).

(继承自 AccessibleObject)
IReflect.GetMember(String, BindingFlags)

获取 MemberInfo 对象数组,这些对象对应于所有公共成员或与指定的名称匹配的所有成员。Gets an array of MemberInfo objects corresponding to all public members or to all members that match a specified name. 有关此成员的说明,请参见 GetMember(String, BindingFlags)For a description of this member, see GetMember(String, BindingFlags).

(继承自 AccessibleObject)
IReflect.GetMembers(BindingFlags)

获取 MemberInfo 对象数组,这些对象对应于所有公共成员或者当前类的所有成员。Gets an array of MemberInfo objects corresponding either to all public members or to all members of the current class. 有关此成员的说明,请参见 GetMembers(BindingFlags)For a description of this member, see GetMembers(BindingFlags).

(继承自 AccessibleObject)
IReflect.GetMethod(String, BindingFlags)

在指定的搜索约束下获取与指定方法对应的 MethodInfo 对象。Gets a MethodInfo object corresponding to a specified method under specified search constraints. 有关此成员的说明,请参见 GetMethod(String, BindingFlags)For a description of this member, see GetMethod(String, BindingFlags).

(继承自 AccessibleObject)
IReflect.GetMethod(String, BindingFlags, Binder, Type[], ParameterModifier[])

获取与指定方法对应的 MethodInfo 对象(使用类型数组从重载方法中进行选择)。Gets a MethodInfo object corresponding to a specified method, using a Type array to choose from among overloaded methods. 有关此成员的说明,请参见 GetMethod(String, BindingFlags, Binder, Type[], ParameterModifier[])For a description of this member, see GetMethod(String, BindingFlags, Binder, Type[], ParameterModifier[]).

(继承自 AccessibleObject)
IReflect.GetMethods(BindingFlags)

获取 MethodInfo 对象的数组,其中包含了所有公共方法或当前类的所有方法。Gets an array of MethodInfo objects with all public methods or all methods of the current class. 有关此成员的说明,请参见 GetMethods(BindingFlags)For a description of this member, see GetMethods(BindingFlags).

(继承自 AccessibleObject)
IReflect.GetProperties(BindingFlags)

获取 PropertyInfo 对象数组,这些对象对应于所有公共属性或当前类的所有属性。Gets an array of PropertyInfo objects corresponding to all public properties or to all properties of the current class. 有关此成员的说明,请参见 GetProperties(BindingFlags)For a description of this member, see GetProperties(BindingFlags).

(继承自 AccessibleObject)
IReflect.GetProperty(String, BindingFlags)

在指定的搜索约束下获取与指定属性对应的 PropertyInfo 对象。Gets a PropertyInfo object corresponding to a specified property under specified search constraints. 有关此成员的说明,请参见 GetProperty(String, BindingFlags)For a description of this member, see GetProperty(String, BindingFlags).

(继承自 AccessibleObject)
IReflect.GetProperty(String, BindingFlags, Binder, Type, Type[], ParameterModifier[])

在指定的搜索约束下获取与指定属性对应的 PropertyInfo 对象。Gets a PropertyInfo object corresponding to a specified property with specified search constraints. 有关此成员的说明,请参见 GetProperty(String, BindingFlags, Binder, Type, Type[], ParameterModifier[])For a description of this member, see GetProperty(String, BindingFlags, Binder, Type, Type[], ParameterModifier[]).

(继承自 AccessibleObject)
IReflect.InvokeMember(String, BindingFlags, Binder, Object, Object[], ParameterModifier[], CultureInfo, String[])

调用指定的成员。Invokes a specified member. 有关此成员的说明,请参见 InvokeMember(String, BindingFlags, Binder, Object, Object[], ParameterModifier[], CultureInfo, String[])For a description of this member, see InvokeMember(String, BindingFlags, Binder, Object, Object[], ParameterModifier[], CultureInfo, String[]).

(继承自 AccessibleObject)
IReflect.UnderlyingSystemType

获取表示 IReflect 对象的基础类型。Gets the underlying type that represents the IReflect object. 有关此成员的说明,请参见 UnderlyingSystemTypeFor a description of this member, see UnderlyingSystemType.

(继承自 AccessibleObject)

适用于

另请参阅