Export (0) Print
Expand All

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

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

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 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft