Control.ControlAccessibleObject 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
提供有关辅助功能应用程序可使用的控件的信息。
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
- 继承
- 继承
- 派生
- 属性
示例
下面的代码示例创建一个从类派生 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 窗体内置了辅助功能支持,并提供有关应用程序的信息,使应用程序能够使用辅助功能客户端应用程序。 辅助功能客户端应用程序的示例包括:屏幕放大和审阅者实用工具、语音输入实用工具、屏幕键盘、备用输入设备和键盘增强实用工具。 有时,需要向辅助功能客户端应用程序提供其他信息。 可通过两种方式提供此附加信息。 若要为现有控件提供有限的辅助功能信息,请设置控件的、AccessibleNameAccessibleDescription和AccessibleDefaultActionDescriptionAccessibleRole属性值,这些值将报告给辅助功能客户端应用程序。 或者,如果需要将更多辅助功能信息包含在控件中,则可以编写派生自 AccessibleObject 或 Control.ControlAccessibleObject 类的自己的类。 例如,如果要编写不派生自公共控件的控件,或者需要控件中的命中测试等操作,则应通过调用CreateAccessibilityInstance该方法为控件创建一个Control.ControlAccessibleObject控件。
备注
如果重写 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 |
获取辅助性对象的快捷键或访问键。 |
Name |
获取或设置可访问对象名称。 |
Owner |
获取辅助性对象的所有者。 |
Parent |
获取辅助性对象的父级。 |
Role |
获取此辅助性对象的角色。 |
State |
获取此辅助性对象的状态。 (继承自 AccessibleObject) |
Value |
获取或设置辅助性对象的值。 (继承自 AccessibleObject) |