Control.ControlAccessibleObject Constructor
Initializes a new instance of the Control.ControlAccessibleObject class.
Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
Parameters
- ownerControl
- Type: System.Windows.Forms.Control
The Control that owns the Control.ControlAccessibleObject.
| Exception | Condition |
|---|---|
| ArgumentNullException | The ownerControl parameter value is null. |
The 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. The derived class, MyCheckBox, has an Appearance of Button by default so it appears as a toggle button. The derived Control.ControlAccessibleObject class, MyCheckBoxControlAccessibleObject, overrides three properties to account for the difference in appearance.
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; } } } }
Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.