Export (0) Print
Expand All

Control.ControlAccessibleObject Class

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

For a list of all members of this type, see Control.ControlAccessibleObject Members.

System.Object
   System.MarshalByRefObject
      System.Windows.Forms.AccessibleObject
         System.Windows.Forms.Control.ControlAccessibleObject

[Visual Basic]
<ComVisible(True)>
Public Class Control.ControlAccessibleObject
   Inherits AccessibleObject
[C#]
[ComVisible(true)]
public class Control.ControlAccessibleObject : AccessibleObject
[C++]
[ComVisible(true)]
public __gc class Control.ControlAccessibleObject : public
   AccessibleObject
[JScript]
public
   ComVisible(true)
class Control.ControlAccessibleObject extends
   AccessibleObject

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Remarks

Windows Forms has accessibility support built in, and provides information about your application that allows 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. There are instances when 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.

Note   If you override the AccessibleObject.GetChild method, you must also override the AccessibleObject.GetChildCount method.
Note   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.

Example

[Visual Basic, C#, C++] The following 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.

[Visual Basic] 
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 appear like 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 
      ' 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(owner As MyCheckBox)
         MyBase.New(owner)
      End Sub
      
      Public Overrides ReadOnly Property DefaultAction() As String
         Get
            ' Return the DefaultAction based upon 
            ' 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
            MyBase.Name = value
         End Set
      End Property
      
      Public Overrides ReadOnly Property Role() As AccessibleRole
         Get
            ' Since the check box appears like a button,
            ' make the Role the same as a button. 
            Return AccessibleRole.PushButton
         End Get
      End Property
   End Class
End Namespace

[C#] 
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;
         }
      }
   }
}

[C++] 
#using <mscorlib.dll>
#using <Accessibility.dll>
#using <System.Drawing.dll>
#using <System.dll>
#using <System.Windows.Forms.dll>

using namespace System;
using namespace System::Windows::Forms;
using namespace System::Drawing;

namespace MyCustomControls {
public __gc class MyCheckBox : public 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 = S"A toggle style button.";
   }

   // Create an instance of the AccessibleObject
   // defined for the 'MyCheckBox' control
protected:
   AccessibleObject* CreateAccessibilityInstance();
};

// Accessible Object* for use with the 'MyCheckBox' control.
private __gc class MyCheckBoxAccessibleObject : public Control::ControlAccessibleObject {
public:
   MyCheckBoxAccessibleObject(MyCheckBox* owner) : ControlAccessibleObject(owner) {
   }

   __property String* get_DefaultAction() {
      // Return the DefaultAction based upon
      // the state of the control.
      if ((dynamic_cast<MyCheckBox*>(Owner))->Checked) {
         return S"Toggle button up";
      } else {
         return S"Toggle button down";
      }
   }

   __property String* get_Name() {
      // Return the Text property of the control
      // if the AccessibleName is 0.
      String* name = Owner->AccessibleName;
      if (name != 0) {
         return name;
      }
      return (dynamic_cast<MyCheckBox*>(Owner))->Text;
   }
   __property void set_Name(String* value) {
      ControlAccessibleObject::set_Name(value);
   }

   __property AccessibleRole get_Role() {
      // Since the check box appears like a button,
      // make the Role the same as a button.
      return AccessibleRole::PushButton;
   }
};

AccessibleObject* MyCheckBox::CreateAccessibilityInstance() {
   return new MyCheckBoxAccessibleObject(this);
}
}

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Namespace: System.Windows.Forms

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

Assembly: System.Windows.Forms (in System.Windows.Forms.dll)

See Also

Control.ControlAccessibleObject Members | System.Windows.Forms Namespace | AccessibleObject | Control.AccessibleName | Control.AccessibleDescription | Control.AccessibleDefaultActionDescription | Control.AccessibleRole

Show:
© 2014 Microsoft