In many cases the required accessibility information can be provided using the following properties of the Control Class in the System.Windows.Forms Namespace: the Control.AccessibleDefaultActionDescription Property, the Control.AccessibleDescription Property, the Control.AccessibleName Property, and the Control.AccessibleRole Property. This feature is almost enough to meet WCAG Success Criterion 4.1.2: Name, Role, Value. WCAG Success Criterion 4.1.2: Name, Role, Value requires that state information be provided as well. Unfortunately, there is not a property in the Control Class for state information.
In many cases, the built in Windows Forms support is sufficient and therefore there is no need to specifically provide state information.
If you do need to provide state information, it will take a bit more effort. In this case, you will need to use the AccessibleObject Class and the Control.CreateAccessibilityInstance Method.
Using the Accessible* Properties of the Control Class
The following code demonstrates the use of the Control.AccessibleDescription Property and the Control.AccessibleName Property of the Control Class.
public MyForm()
{
// Create a 'MyCheckBox' control and
// display an image on it.
MyCustomControls.MyCheckBox myCheckBox = new MyCustomControls.MyCheckBox();
myCheckBox.Location = new Point(5,5);
myCheckBox.Image = Image.FromFile(
Application.CommonAppDataPath + "\\Preview.jpg");
// Set the AccessibleName property
// since there is no Text displayed.
myCheckBox.AccessibleName = "Preview";
myCheckBox.AccessibleDescription = "A toggle button used to show the document preview.";
this.Controls.Add(myCheckBox);
}
In this case, the checkbox object provides the state. However, since an image is used instead of text, it does not provide the name. Therefore the Control.AccessibleDescription Property and the Control.AccessibleName Property of the Control Class are used. In addition, these properties suffice to meet WCAG Success Criterion 4.1.2: Name, Role, Value.
References
- AccessibleObject Class
- AccessibleRole Enum
- Control Class
- Control.AccessibilityObject Property
- Control.AccessibleDefaultActionDescription Property
- Control.AccessibleDescription Property
- Control.AccessibleName Property
- Control.AccessibleRole Property
- Control.ControlAccessibleObject Class
- Control.CreateAccessibilityInstance Method
- System.Windows.Forms Namespace