SUMMARY
This step-by-step article describes how to create an
accessible control that is derived from the
Control.ControlAccessibleObject class in Microsoft Visual Basic .NET or in Microsoft Visual Basic 2005.
back to the topRequirements
This article assumes that you are
familiar with the following topics:
- Microsoft Visual Basic .NET or Microsoft Visual Basic 2005
- Microsoft Active Accessibility
The following list outlines the
recommended hardware, software, network infrastructure, and service packs that
you need:
- Microsoft Windows 2000, Microsoft Windows XP, or Microsoft
Windows Server 2003
- Microsoft Visual Basic .NET or Microsoft Visual Basic 2005
back to the topBackground information
Microsoft Active Accessibility is a developer technology that
may help to improve the way that programs and operating systems work with assistive
technology products. This technology was first integrated in the Microsoft Windows operating
system in Microsoft Windows 98. Microsoft continues to update this technology with each new
Windows release.
Microsoft Windows Forms has built-in Active Accessibility support. Windows Forms provides information about your application that permits your application to work with
assistive technology products. You can use the following property values of a control to provide additional information to assistive technology products:
- AccessibleName
- AccessibleDescription
- AccessibleDefaultActionDescription
- AccessibleRole
Alternatively, if you require more Active Accessibility information to be included
with your control, you can write your own class that is derived from the
AccessibleObject class or from the
Control.ControlAccessibleObject class.
The
Control.ControlAccessibleObject class inherits from the
AccessibleObject class.
AccessibleObject enables you to provide information about a control to an assistive technology product.
Control.ControlAccessibleObject enables you to provide information about a control to an assistive technology product by exposing a set of standard
properties. For example,
Control.ControlAccessibleObject may expose the
Role property, the
Location property, and others. Active Accessibility uses these
properties to expose information to assistive technology products.
Active Accessibility uses Windows Events
(WinEvents) to notify assistive technology products of user interface
changes in a control, such as a change in the name, in the state, or in the value of a user interface
element.
For more information about Microsoft Active Accessibility
architecture, visit the following Microsoft Web sites:
back to the
topCreate a sample control
To create a custom
CheckBox control (
MyCheckBox) and to create a custom
Control.ControlAccessibleObject class (
MyCheckBoxAccessibleObject) that the custom
CheckBox control uses to provide accessibility
information to Active Accessibility applications, follow these steps:
- Open Microsoft Visual Studio .NET or Microsoft Visual Studio 2005.
- On the File menu, click
New, and then click Project to display the
New Project dialog box.
- In the Project Type window, click
Visual Basic Projects.
Note In Visual Studio 2005, click Visual Basic under Project Types. - In the Templates
window, click Windows Control Library.
- In the Name box, type
MyCheckBox, and then click OK
to create the project.
- Add a reference to the Active Accessibility assembly that is installed
with the Microsoft .NET Framework. To do this, follow these steps:
- On the
Project menu, click Add Reference.
- On the
.NET tab, double-click Accessibility.dll.
- Click OK to close the
Add Reference dialog box.
Note The AccessibleObject class implements the IAccessible interface. The IAccessible interface is defined by the Active Accessibility
assembly. Therefore, you must add a reference to the Active Accessibility assembly that is installed with the .NET Framework. - Replace the content of UserControl1.vb with the following
code:
Imports System
Imports System.Windows.Forms
Imports Accessibility
Imports System.Drawing
Namespace MyCustomControls
Public Class MyCheckBox
Inherits CheckBox
Public Sub New()
' Make the check box look similar to 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 that is
' 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(ByVal owner As MyCheckBox)
MyBase.New(owner)
End Sub
Public Overrides ReadOnly Property DefaultAction() As String
Get
' Return the DefaultAction based on
' 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 Not (accessibleName Is Nothing) Then
Return accessibleName
End If
Return CType(Owner, MyCheckBox).Text
End Get
Set(ByVal Value As String)
MyBase.Name = value
End Set
End Property
Public Overrides ReadOnly Property Role() As AccessibleRole
Get
' Because the check box looks similar to a button and functions like a button,
' make the Role the same as a button.
Return AccessibleRole.PushButton
End Get
End Property
End Class
End Namespace
- On the Build menu, click Build
Solution to build the control.
back to the topTest the sample control
- Create a new Visual Basic .NET or Visual Basic 2005 Windows Application project in
Visual Studio .NET or in Visual Basic 2005.
- On the View menu, click
Toolbox.
- Right-click the toolbox.
- If you are using Microsoft Visual Studio .NET
2002, click Customize Toolbox.
If you are using
Microsoft Visual Studio .NET 2003, click Add/Remove Items.
If you are using
Microsoft Visual Studio 2005, click Choose Items. - In the Customize Toolbox dialog box,
click the .NET Framework Components tab, and then click
the Browse button to locate the control assembly that you created in the "Create a sample control"
section of this article.
Note The control assembly is MyCheckBox.dll in the code sample. - Click OK to close the Customize
Toolbox dialog box.
- Add the MyCheckBox control to the form.
- Add a Button control to the form.
By default,
button1 is added to the form.
Add the following code in the
Click event handler of the button:MsgBox("Role: " + MyCheckBox1.AccessibilityObject.Role.ToString() + vbCrLf _
+ "Name: " + MyCheckBox1.AccessibilityObject.Name.ToString() + vbCrLf _
+ "DefaultAction:" + MyCheckBox1.AccessibilityObject.DefaultAction.ToString())
- Press the F5 key to build the application and to run the
application.
- When the application starts, press button1
on the form.
You receive the following message:Role: PushButton
Name: MyCheckBox1
DefaultAction: Toggle button dow
back to the
top