Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

Control.ControlAccessibleObject Class

Provides information about a control that can be used by an accessibility application.

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

[ComVisibleAttribute(true)] 
public class ControlAccessibleObject : AccessibleObject
/** @attribute ComVisibleAttribute(true) */ 
public class ControlAccessibleObject extends AccessibleObject
ComVisibleAttribute(true) 
public class ControlAccessibleObject extends AccessibleObject
Not applicable.

Windows Forms has accessibility support built in, and provides information about your application that enables it to work with accessibility client applications. Examples of accessibility client applications are: screen enlarger and reviewer utilities, voice input utilities, on-screen keyboards, alternative input devices, and keyboard enhancement utilities. Sometimes you will want to provide additional information to accessibility client applications. There are two ways of providing this additional information. To provide limited accessibility information for existing controls, set the control's AccessibleName, AccessibleDescription, AccessibleDefaultActionDescription, and AccessibleRole property values, which will be reported to accessibility client applications. Alternatively, if you require more accessibility information to be included with your control, you can write your own class deriving from the AccessibleObject or Control.ControlAccessibleObject classes. For example, if you are writing your own control that is not derived from the common controls or you require such operations as hit testing within your control, you should create a Control.ControlAccessibleObject for your control by calling the CreateAccessibilityInstance method.

NoteNote:

If you override the AccessibleObject.GetChild method, you must also override the AccessibleObject.GetChildCount method. To get or set the AccessibilityObject property, you must add a reference to the Accessibility assembly installed with the .NET Framework.

For more information about accessible objects, see the Active Accessibility section of the MSDN Library.

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;
         }
      }
   }
}

package MyCustomControls;
import System.*;
import System.Windows.Forms.*;
import Accessibility.*;
import System.Drawing.*;

public class MyCheckBox extends CheckBox
{
    public MyCheckBox()
    {
        // Make the check box appear like a toggle button.
        this.set_Appearance(get_Appearance().Button);
        // Center the text on the button.
        this.set_TextAlign(ContentAlignment.MiddleCenter);
        // Set the AccessibleDescription text.
        this.set_AccessibleDescription("A toggle style button.");
    } //MyCheckBox

    // Create an instance of the AccessibleObject 
    // defined for the 'MyCheckBox' control
    protected AccessibleObject CreateAccessibilityInstance()
    {
        return new MyCheckBoxAccessibleObject(this);
    } //CreateAccessibilityInstance
} //MyCheckBox

// Accessible object for use with the 'MyCheckBox' control.
class MyCheckBoxAccessibleObject extends Control.ControlAccessibleObject
{
    public MyCheckBoxAccessibleObject(MyCheckBox owner)
    {
         super(owner);
    } //MyCheckBoxAccessibleObject

    /** @property 
     */
    public String get_DefaultAction()
    {
        // Return the DefaultAction based upon 
        // the state of the control.
        if (((MyCheckBox)get_Owner()).get_Checked()) {
            return "Toggle button up";
        }
        else {
            return "Toggle button down";
        }
    } //get_DefaultAction

    /** @property 
     */
    public String get_Name()
    {
        // Return the Text property of the control 
        // if the AccessibleName is null.
        String name = get_Owner().get_AccessibleName();
        if (name != null) {
            return name;
        }
        return ((MyCheckBox)get_Owner()).get_Text();
    } //get_Name

    /** @property 
     */
    public void set_Name(String value)
    {
        super.set_Name(value);
    } //set_Name

    /** @property 
     */
    public AccessibleRole get_Role()
    {
        // Since the check box appears like a button,
        // make the Role the same as a button.
        return AccessibleRole.PushButton;
    } //get_Role
} //MyCheckBoxAccessibleObject

System.Object
   System.MarshalByRefObject
     System.Runtime.InteropServices.StandardOleMarshalObject
       System.Windows.Forms.AccessibleObject
        System.Windows.Forms.Control.ControlAccessibleObject
           Derived Classes
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.