แก้ไข

แชร์ผ่าน


Control.ControlAccessibleObject Class

Definition

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

public: ref class Control::ControlAccessibleObject : System::Windows::Forms::AccessibleObject
[System.Runtime.InteropServices.ComVisible(true)]
public class Control.ControlAccessibleObject : System.Windows.Forms.AccessibleObject
public class Control.ControlAccessibleObject : System.Windows.Forms.AccessibleObject
[<System.Runtime.InteropServices.ComVisible(true)>]
type Control.ControlAccessibleObject = class
    inherit AccessibleObject
type Control.ControlAccessibleObject = class
    inherit AccessibleObject
Public Class Control.ControlAccessibleObject
Inherits AccessibleObject
Inheritance
Control.ControlAccessibleObject
Inheritance
Derived
Attributes

Examples

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 <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 ref 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 = "A toggle style button.";
      }

   protected:

      // Create an instance of the AccessibleObject
      // defined for the 'MyCheckBox' control
      virtual AccessibleObject^ CreateAccessibilityInstance() override;
   };

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

      property String^ DefaultAction 
      {
         virtual String^ get() override
         {
            // Return the DefaultAction based upon
            // the state of the control.
            if ( (dynamic_cast<MyCheckBox^>(Owner))->Checked )
            {
               return "Toggle button up";
            }
            else
            {
               return "Toggle button down";
            }
         }
      }

      property String^ Name 
      {
         virtual String^ get() override
         {
            // Return the Text property of the control
            // if the AccessibleName is 0.
            String^ name = Owner->AccessibleName;
            if ( name != nullptr )
            {
               return name;
            }

            return (dynamic_cast<MyCheckBox^>(Owner))->Text;
         }

         virtual void set( String^ value ) override
         {
            ControlAccessibleObject::Name = value;
         }
      }

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

   AccessibleObject^ MyCheckBox::CreateAccessibilityInstance()
   {
      return gcnew MyCheckBoxAccessibleObject( this );
   }
}
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;
         }
      }
   }
}
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 (accessibleName IsNot 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

Remarks

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.

Note

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 Microsoft Active Accessibility.

Constructors

Control.ControlAccessibleObject(Control)

Initializes a new instance of the Control.ControlAccessibleObject class.

Properties

Bounds

Gets the location and size of the accessible object.

(Inherited from AccessibleObject)
DefaultAction

Gets a string that describes the default action of the object. Not all objects have a default action.

Description

Gets the description of the Control.ControlAccessibleObject.

Handle

Gets or sets the handle of the accessible object.

Help

Gets the description of what the object does or how the object is used.

KeyboardShortcut

Gets the object shortcut key or access key for an accessible object.

Name

Gets or sets the accessible object name.

Owner

Gets the owner of the accessible object.

Parent

Gets the parent of an accessible object.

Role

Gets the role of this accessible object.

State

Gets the state of this accessible object.

(Inherited from AccessibleObject)
Value

Gets or sets the value of an accessible object.

(Inherited from AccessibleObject)

Methods

CreateObjRef(Type)

Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.

(Inherited from MarshalByRefObject)
DoDefaultAction()

Performs the default action associated with this accessible object.

(Inherited from AccessibleObject)
Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetChild(Int32)

Retrieves the accessible child corresponding to the specified index.

(Inherited from AccessibleObject)
GetChildCount()

Retrieves the number of children belonging to an accessible object.

(Inherited from AccessibleObject)
GetFocused()

Retrieves the object that has the keyboard focus.

(Inherited from AccessibleObject)
GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetHelpTopic(String)

Gets an identifier for a Help topic and the path to the Help file associated with this accessible object.

GetLifetimeService()
Obsolete.

Retrieves the current lifetime service object that controls the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
GetSelected()

Retrieves the currently selected child.

(Inherited from AccessibleObject)
GetType()

Gets the Type of the current instance.

(Inherited from Object)
HitTest(Int32, Int32)

Retrieves the child object at the specified screen coordinates.

(Inherited from AccessibleObject)
InitializeLifetimeService()
Obsolete.

Obtains a lifetime service object to control the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
MemberwiseClone(Boolean)

Creates a shallow copy of the current MarshalByRefObject object.

(Inherited from MarshalByRefObject)
Navigate(AccessibleNavigation)

Navigates to another accessible object.

(Inherited from AccessibleObject)
NotifyClients(AccessibleEvents, Int32, Int32)

Notifies the accessibility client applications of the specified AccessibleEvents for the specified child control, giving the identification of the AccessibleObject.

NotifyClients(AccessibleEvents, Int32)

Notifies the accessibility client applications of the specified AccessibleEvents for the specified child control.

NotifyClients(AccessibleEvents)

Notifies accessibility client applications of the specified AccessibleEvents.

RaiseAutomationNotification(AutomationNotificationKind, AutomationNotificationProcessing, String)

Raises the UI automation notification event.

(Inherited from AccessibleObject)
RaiseLiveRegionChanged()

Raises the LiveRegionChanged UI automation event.

RaiseLiveRegionChanged()

Raises the LiveRegionChanged UI automation event.

(Inherited from AccessibleObject)
Select(AccessibleSelection)

Modifies the selection or moves the keyboard focus of the accessible object.

(Inherited from AccessibleObject)
ToString()

Returns a string that represents the current object.

UseStdAccessibleObjects(IntPtr, Int32)

Associates an object with an instance of an AccessibleObject based on the handle and the object id of the object.

(Inherited from AccessibleObject)
UseStdAccessibleObjects(IntPtr)

Associates an object with an instance of an AccessibleObject based on the handle of the object.

(Inherited from AccessibleObject)

Explicit Interface Implementations

IAccessible.accChildCount

Gets the number of child interfaces that belong to this object. For a description of this member, see accChildCount.

(Inherited from AccessibleObject)
IAccessible.accDoDefaultAction(Object)

Performs the specified object's default action. Not all objects have a default action. For a description of this member, see accDoDefaultAction(Object).

(Inherited from AccessibleObject)
IAccessible.accFocus

Gets the object that has the keyboard focus. For a description of this member, see accFocus.

(Inherited from AccessibleObject)
IAccessible.accHitTest(Int32, Int32)

Gets the child object at the specified screen coordinates. For a description of this member, see accHitTest(Int32, Int32).

(Inherited from AccessibleObject)
IAccessible.accLocation(Int32, Int32, Int32, Int32, Object)

Gets the object's current screen location. For a description of this member, see accLocation(Int32, Int32, Int32, Int32, Object).

(Inherited from AccessibleObject)
IAccessible.accNavigate(Int32, Object)

Navigates to an accessible object relative to the current object. For a description of this member, see accNavigate(Int32, Object).

(Inherited from AccessibleObject)
IAccessible.accParent

Gets the parent accessible object of this object. For a description of this member, see accParent.

(Inherited from AccessibleObject)
IAccessible.accSelect(Int32, Object)

Modifies the selection or moves the keyboard focus of the accessible object. For a description of this member, see accSelect(Int32, Object).

(Inherited from AccessibleObject)
IAccessible.accSelection

Gets the selected child objects of an accessible object. For a description of this member, see accSelection.

(Inherited from AccessibleObject)
IReflect.GetField(String, BindingFlags)

Gets the FieldInfo object corresponding to the specified field and binding flag. For a description of this member, see GetField(String, BindingFlags).

(Inherited from AccessibleObject)
IReflect.GetFields(BindingFlags)

Gets an array of FieldInfo objects corresponding to all fields of the current class. For a description of this member, see GetFields(BindingFlags).

(Inherited from AccessibleObject)
IReflect.GetMember(String, BindingFlags)

Gets an array of MemberInfo objects corresponding to all public members or to all members that match a specified name. For a description of this member, see GetMember(String, BindingFlags).

(Inherited from AccessibleObject)
IReflect.GetMembers(BindingFlags)

Gets an array of MemberInfo objects corresponding either to all public members or to all members of the current class. For a description of this member, see GetMembers(BindingFlags).

(Inherited from AccessibleObject)
IReflect.GetMethod(String, BindingFlags, Binder, Type[], ParameterModifier[])

Gets a MethodInfo object corresponding to a specified method, using a Type array to choose from among overloaded methods. For a description of this member, see GetMethod(String, BindingFlags, Binder, Type[], ParameterModifier[]).

(Inherited from AccessibleObject)
IReflect.GetMethod(String, BindingFlags)

Gets a MethodInfo object corresponding to a specified method under specified search constraints. For a description of this member, see GetMethod(String, BindingFlags).

(Inherited from AccessibleObject)
IReflect.GetMethods(BindingFlags)

Gets an array of MethodInfo objects with all public methods or all methods of the current class. For a description of this member, see GetMethods(BindingFlags).

(Inherited from AccessibleObject)
IReflect.GetProperties(BindingFlags)

Gets an array of PropertyInfo objects corresponding to all public properties or to all properties of the current class. For a description of this member, see GetProperties(BindingFlags).

(Inherited from AccessibleObject)
IReflect.GetProperty(String, BindingFlags, Binder, Type, Type[], ParameterModifier[])

Gets a PropertyInfo object corresponding to a specified property with specified search constraints. For a description of this member, see GetProperty(String, BindingFlags, Binder, Type, Type[], ParameterModifier[]).

(Inherited from AccessibleObject)
IReflect.GetProperty(String, BindingFlags)

Gets a PropertyInfo object corresponding to a specified property under specified search constraints. For a description of this member, see GetProperty(String, BindingFlags).

(Inherited from AccessibleObject)
IReflect.InvokeMember(String, BindingFlags, Binder, Object, Object[], ParameterModifier[], CultureInfo, String[])

Invokes a specified member. For a description of this member, see InvokeMember(String, BindingFlags, Binder, Object, Object[], ParameterModifier[], CultureInfo, String[]).

(Inherited from AccessibleObject)
IReflect.UnderlyingSystemType

Gets the underlying type that represents the IReflect object. For a description of this member, see UnderlyingSystemType.

(Inherited from AccessibleObject)

Applies to

See also