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預設有 Appearance 的 , Button 因此它看起來像是切換按鈕。 導出 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 表單內建無障礙支援,並提供應用程式相關資訊,使其能與無障礙客戶端應用程式協同運作。 無障礙客戶端應用範例包括:螢幕放大與審查工具、語音輸入工具、螢幕鍵盤、替代輸入裝置及鍵盤增強工具。 有時你會想為無障礙客戶端應用程式提供額外資訊。 提供這些額外資訊有兩種方式。 為現有控制項提供有限的無障礙資訊,請設定控制項的 AccessibleName、 AccessibleDescription、 AccessibleDefaultActionDescription及 AccessibleRole 屬性值,這些值將回報給無障礙客戶端應用程式。 或者,如果你需要更多無障礙資訊來控制,也可以自行撰寫由 AccessibleObject or Control.ControlAccessibleObject 類別衍生的類別。 例如,如果你自己寫的控制項並非源自常見控制,或需要在控制範圍內進行擊中測試等操作,你應該透過呼叫該CreateAccessibilityInstance方法來建立控制項的 aControl.ControlAccessibleObject。
備註
如果你覆寫了這個方法, AccessibleObject.GetChild 你也必須同時覆寫這個 AccessibleObject.GetChildCount 方法。 要取得或設定該 AccessibilityObject 屬性,必須新增一個參考到 .NET Framework 所安裝的 Accessibility 組件語言。
欲了解更多無障礙物件相關資訊,請參閱 Microsoft 主動無障礙功能。
建構函式
| 名稱 | Description |
|---|---|
| Control.ControlAccessibleObject(Control) |
初始化 Control.ControlAccessibleObject 類別的新執行個體。 |
屬性
| 名稱 | Description |
|---|---|
| Bounds |
取得可存取物件的位置與大小。 (繼承來源 AccessibleObject) |
| DefaultAction |
會取得一個字串來描述物件的預設動作。 並非所有物件都有預設動作。 |
| Description |
取得 的描述 Control.ControlAccessibleObject。 |
| Handle |
取得或設定可存取物件的 handle。 |
| Help |
會取得物件的功能或使用方式的描述。 |
| KeyboardShortcut |
取得物件快捷鍵或存取鍵,適用於可存取物件。 |
| Name |
取得或設定可存取的物件名稱。 |
| Owner |
取得可存取物件的擁有者。 |
| Parent |
取得可存取物件的父節點。 |
| Role |
這就成為這個可及物件的角色。 |
| State |
取得這個可存取物件的狀態。 (繼承來源 AccessibleObject) |
| Value |
取得或設定可存取物件的值。 (繼承來源 AccessibleObject) |