Export (0) Print
Expand All

AccessibleObject Class

Provides information that accessibility applications use to adjust an application's user interface (UI) for users with impairments.

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

[ComVisibleAttribute(true)]
public class AccessibleObject : StandardOleMarshalObject, 
	IReflect, IAccessible

The AccessibleObject type exposes the following members.

  NameDescription
Public methodAccessibleObjectInitializes a new instance of the AccessibleObject class.
Top

  NameDescription
Public propertyBoundsGets the location and size of the accessible object.
Public propertyDefaultActionGets a string that describes the default action of the object. Not all objects have a default action.
Public propertyDescriptionGets a string that describes the visual appearance of the specified object. Not all objects have a description.
Public propertyHelpGets a description of what the object does or how the object is used.
Public propertyKeyboardShortcutGets the shortcut key or access key for the accessible object.
Public propertyNameGets or sets the object name.
Public propertyParentGets the parent of an accessible object.
Public propertyRoleGets the role of this accessible object.
Public propertyStateGets the state of this accessible object.
Public propertyValueGets or sets the value of an accessible object.
Top

  NameDescription
Public methodCreateObjRefCreates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object. (Inherited from MarshalByRefObject.)
Public methodDoDefaultActionPerforms the default action associated with this accessible object.
Public methodEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetChildRetrieves the accessible child corresponding to the specified index.
Public methodGetChildCountRetrieves the number of children belonging to an accessible object.
Public methodGetFocusedRetrieves the object that has the keyboard focus.
Public methodGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodGetHelpTopicGets an identifier for a Help topic identifier and the path to the Help file associated with this accessible object.
Public methodGetLifetimeServiceRetrieves the current lifetime service object that controls the lifetime policy for this instance. (Inherited from MarshalByRefObject.)
Public methodGetSelectedRetrieves the currently selected child.
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodHitTestRetrieves the child object at the specified screen coordinates.
Public methodInitializeLifetimeServiceObtains a lifetime service object to control the lifetime policy for this instance. (Inherited from MarshalByRefObject.)
Protected methodMemberwiseClone()Creates a shallow copy of the current Object. (Inherited from Object.)
Protected methodMemberwiseClone(Boolean)Creates a shallow copy of the current MarshalByRefObject object. (Inherited from MarshalByRefObject.)
Public methodNavigateNavigates to another accessible object.
Public methodSelectModifies the selection or moves the keyboard focus of the accessible object.
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Protected methodUseStdAccessibleObjects(IntPtr)Infrastructure. Associates an object with an instance of an AccessibleObject based on the handle of the object.
Protected methodUseStdAccessibleObjects(IntPtr, Int32)Infrastructure. Associates an object with an instance of an AccessibleObject based on the handle and the object id of the object.
Top

  NameDescription
Explicit interface implemetationPrivate propertyIAccessible.accChildCountInfrastructure. Gets the number of child interfaces that belong to this object. For a description of this member, see IAccessible.accChildCount.
Explicit interface implemetationPrivate methodIAccessible.accDoDefaultActionInfrastructure. Performs the specified object's default action. Not all objects have a default action. For a description of this member, see IAccessible.accDoDefaultAction.
Explicit interface implemetationPrivate propertyIAccessible.accFocusInfrastructure. Gets the object that has the keyboard focus. For a description of this member, see IAccessible.accFocus.
Explicit interface implemetationPrivate methodIAccessible.accHitTestInfrastructure. Gets the child object at the specified screen coordinates. For a description of this member, see IAccessible.accHitTest.
Explicit interface implemetationPrivate methodIAccessible.accLocationInfrastructure. Gets the object's current screen location. For a description of this member, see IAccessible.accLocation.
Explicit interface implemetationPrivate methodIAccessible.accNavigateInfrastructure. Navigates to an accessible object relative to the current object. For a description of this member, see IAccessible.accNavigate.
Explicit interface implemetationPrivate propertyIAccessible.accParentInfrastructure. Gets the parent accessible object of this object. For a description of this member, see IAccessible.accParent.
Explicit interface implemetationPrivate methodIAccessible.accSelectInfrastructure. Modifies the selection or moves the keyboard focus of the accessible object. For a description of this member, see IAccessible.accSelect.
Explicit interface implemetationPrivate propertyIAccessible.accSelectionInfrastructure. Gets the selected child objects of an accessible object. For a description of this member, see IAccessible.accSelection.
Explicit interface implemetationPrivate methodIReflect.GetFieldInfrastructure. Gets the System.Reflection.FieldInfo object corresponding to the specified field and binding flag. For a description of this member, see IReflect.GetField.
Explicit interface implemetationPrivate methodIReflect.GetFieldsInfrastructure. Gets an array of System.Reflection.FieldInfo objects corresponding to all fields of the current class. For a description of this member, see IReflect.GetFields.
Explicit interface implemetationPrivate methodIReflect.GetMemberInfrastructure. Gets an array of System.Reflection.MemberInfo objects corresponding to all public members or to all members that match a specified name. For a description of this member, see IReflect.GetMember.
Explicit interface implemetationPrivate methodIReflect.GetMembersInfrastructure. Gets an array of System.Reflection.MemberInfo objects corresponding either to all public members or to all members of the current class. For a description of this member, see IReflect.GetMembers.
Explicit interface implemetationPrivate methodIReflect.GetMethod(String, BindingFlags)Infrastructure. Gets a System.Reflection.MethodInfo object corresponding to a specified method under specified search constraints. For a description of this member, see IReflect.GetMethod.
Explicit interface implemetationPrivate methodIReflect.GetMethod(String, BindingFlags, Binder, Type[], ParameterModifier[])Infrastructure. Gets a System.Reflection.MethodInfo object corresponding to a specified method, using a Type array to choose from among overloaded methods. For a description of this member, see IReflect.GetMethod.
Explicit interface implemetationPrivate methodIReflect.GetMethodsInfrastructure. Gets an array of System.Reflection.MethodInfo objects with all public methods or all methods of the current class. For a description of this member, see IReflect.GetMethods.
Explicit interface implemetationPrivate methodIReflect.GetPropertiesInfrastructure. Gets an array of System.Reflection.PropertyInfo objects corresponding to all public properties or to all properties of the current class. For a description of this member, see IReflect.GetProperties.
Explicit interface implemetationPrivate methodIReflect.GetProperty(String, BindingFlags)Infrastructure. Gets a System.Reflection.PropertyInfo object corresponding to a specified property under specified search constraints. For a description of this member, see IReflect.GetProperty.
Explicit interface implemetationPrivate methodIReflect.GetProperty(String, BindingFlags, Binder, Type, Type[], ParameterModifier[])Infrastructure. Gets a System.Reflection.PropertyInfo object corresponding to a specified property with specified search constraints. For a description of this member, see IReflect.GetProperty.
Explicit interface implemetationPrivate methodIReflect.InvokeMemberInfrastructure. Invokes a specified member. For a description of this member, see IReflect.InvokeMember.
Explicit interface implemetationPrivate propertyIReflect.UnderlyingSystemTypeInfrastructure. Gets the underlying type that represents the IReflect object. For a description of this member, see IReflect.UnderlyingSystemType.
Top

Accessibility applications can adjust features of the application to improve usability for users with disabilities.

For users who are visually impaired, you can adjust software and operating system features to comply with their needs. For example, you can enlarge text and images and render them with a contrast. In addition, you can accommodate color-blindness with the appropriate use of colors. For users who are severely visually impaired, computers are accessible with screen review aids that translate on-screen text to speech or to a dynamic, refreshable, Braille display.

For users who are hard of hearing, you can design programs that use visual cues, such as a flashing toolbar; or you can display spoken messages as text. For example, when turned on, the SoundSentry feature, an accessibility option in Control Panel, provides a visual warning whenever the system makes an alarm sound.

For users with motion disabilities, you can design controls that refine or eliminate keyboard and mouse use, thereby improving computer accessibility. Control Panel offers assistance. For example, one alternative is to use the numeric keypad instead of the mouse for navigation. Another option, called StickyKeys, enables users who cannot hold down two or more keys at a time (such as CTRL+P) to get the same result by typing one key at a time.

For users with cognitive and language disabilities, you can design software programs to better accommodate their needs. For example, using conspicuous or cued sequencing, uncomplicated displays, fewer words, and a reading level targeted to elementary school standards can benefit these users.

For users with seizure disorders, you can design software programs to eliminate seizure provoking patterns.

For more information about accessibility, including information about accessibility applications, see the documentation for Microsoft Accessibility in the MSDN library or at the Microsoft Web site.

NoteNote

To use the AccessibleObject, you must add a reference to the Accessibility assembly installed with the .NET Framework. Windows Forms only supports Active Accessibility 2.0.

Notes to Inheritors

When you inherit from this class, you can override all the members.

The following code example demonstrates the creation of an accessibility-aware chart control, using the AccessibleObject and Control.ControlAccessibleObject classes to expose accessible information. The control plots two curves along with a legend. The ChartControlAccessibleObject class, which derives from ControlAccessibleObject, is used in the CreateAccessibilityInstance method to provide custom accessible information for the chart control. Because the chart legend is not an actual Control -based control, but instead is drawn by the chart control, it does not have any built-in accessible information. Because of this, the ChartControlAccessibleObject class overrides the GetChild method to return the CurveLegendAccessibleObject that represents accessible information for each part of the legend. When an accessible-aware application uses this control, the control can provide the necessary accessible information.

using System;
using System.Drawing;
using System.Windows.Forms;

namespace ChartControl
{
    public class Form1 : System.Windows.Forms.Form
    {
        // Test out the Chart Control. 
        private ChartControl chart1;

        [STAThread]
        static void Main() 
        {
            Application.Run(new Form1());
        }

        public Form1() {
            // Create a chart control and add it to the form. 
            this.chart1 = new ChartControl();
            this.ClientSize = new System.Drawing.Size(920, 566);

            this.chart1.Location = new System.Drawing.Point(47, 16);
            this.chart1.Size = new System.Drawing.Size(600, 400);

            this.Controls.Add(this.chart1);
        }
    }

    // Declare a chart control that demonstrates accessibility in Windows Forms. 
    public class ChartControl : System.Windows.Forms.UserControl
    {
        private CurveLegend legend1;
        private CurveLegend legend2; 

        public ChartControl()
        {
            // The ChartControl draws the chart in the OnPaint override.
            SetStyle(ControlStyles.ResizeRedraw, true);
            SetStyle(ControlStyles.DoubleBuffer, true);
            SetStyle(ControlStyles.AllPaintingInWmPaint, true);

            this.BackColor = System.Drawing.Color.White;
            this.Name = "ChartControl";

            this.Click += new System.EventHandler(this.ChartControl_Click);
            this.QueryAccessibilityHelp += 
                new System.Windows.Forms.QueryAccessibilityHelpEventHandler(
                                        this.ChartControl_QueryAccessibilityHelp);

            // The CurveLengend is not Control-based, it just 
            // represents the parts of the legend.
            legend1 = new CurveLegend(this, "A");
            legend1.Location = new Point(20, 30);
            legend2 = new CurveLegend(this, "B");        
            legend2.Location = new Point(20, 50);
        }

        // Overridden to return the custom AccessibleObject  
        // for the entire chart. 
        protected override AccessibleObject CreateAccessibilityInstance() 
        {            
            return new ChartControlAccessibleObject(this);
        }

        protected override void OnPaint(PaintEventArgs e) 
        {
            // The ChartControl draws the chart in the OnPaint override. 
            base.OnPaint(e);

            Rectangle bounds = this.ClientRectangle;
            int border = 5;

            // Draws the legends first.
            StringFormat format = new StringFormat();
            format.Alignment = StringAlignment.Center;
            format.LineAlignment = StringAlignment.Center;

            if (legend1 != null) {
                if (legend1.Selected) {
                    e.Graphics.FillRectangle(new SolidBrush(Color.Blue), legend1.Bounds);
                } else {
                    e.Graphics.DrawRectangle(Pens.Blue, legend1.Bounds);
                }

                e.Graphics.DrawString(legend1.Name, this.Font, Brushes.Black, legend1.Bounds, format);                
            }
            if (legend2 != null) {
                if (legend2.Selected) {
                    e.Graphics.FillRectangle(new SolidBrush(Color.Red), legend2.Bounds);
                } else {
                    e.Graphics.DrawRectangle(Pens.Red, legend2.Bounds);
                }
                e.Graphics.DrawString(legend2.Name, this.Font, Brushes.Black, legend2.Bounds, format);
            }            

            // Charts out the actual curves that represent data in the Chart.
            bounds.Inflate(-border, -border);
            Point[] curve1 = new Point[] {new Point(bounds.Left, bounds.Bottom),
                            new Point(bounds.Left + bounds.Width / 3, bounds.Top + bounds.Height / 5),
                            new Point(bounds.Right - bounds.Width / 3, (bounds.Top + bounds.Bottom) / 2),
                            new Point(bounds.Right, bounds.Top)};

            Point[] curve2 = new Point[] {new Point(bounds.Left, bounds.Bottom - bounds.Height / 3),
                            new Point(bounds.Left + bounds.Width / 3, bounds.Top + bounds.Height / 5),
                            new Point(bounds.Right - bounds.Width / 3, (bounds.Top + bounds.Bottom) / 2),
                            new Point(bounds.Right, bounds.Top + bounds.Height / 2)};

            // Draws the actual curve only if it is selected. 
            if (legend1.Selected) e.Graphics.DrawCurve(Pens.Blue, curve1);
            if (legend2.Selected) e.Graphics.DrawCurve(Pens.Red, curve2);

            e.Graphics.DrawRectangle(Pens.Blue, bounds);            
        }

        // Handles the QueryAccessibilityHelp event. 
        private void ChartControl_QueryAccessibilityHelp(object sender, 
                                    System.Windows.Forms.QueryAccessibilityHelpEventArgs e)
        {            
            e.HelpString = "Displays chart data";
        }          

        // Handles the Click event for the chart.  
        // Toggles the selection of whatever legend was clicked on 
        private void ChartControl_Click(object sender, System.EventArgs e)
        {
            Point pt = this.PointToClient(Control.MousePosition);
            if (legend1.Bounds.Contains(pt)) {
                legend1.Selected = !legend1.Selected;

            } else if (legend2.Bounds.Contains(pt)) {
                legend2.Selected = !legend2.Selected;
            }
        }

        // Gets an array of CurveLengends used in the Chart. 
        public CurveLegend[] Legends
        {   
            get {                
                return new CurveLegend[] { legend1, legend2 };
            }            
        }                

        // Inner class ChartControlAccessibleObject represents accessible information associated with the ChartControl. 
        // The ChartControlAccessibleObject is returned in the ChartControl.CreateAccessibilityInstance override. 
        public class ChartControlAccessibleObject : ControlAccessibleObject
        {
            ChartControl chartControl;

            public ChartControlAccessibleObject(ChartControl ctrl) : base(ctrl) 
            {
                chartControl = ctrl;
            }

            // Gets the role for the Chart. This is used by accessibility programs. 
            public override AccessibleRole Role
            {  
                get {
                    return AccessibleRole.Chart;
                }
            }

            // Gets the state for the Chart. This is used by accessibility programs. 
            public override AccessibleStates State
            {  
                get {                    
                    return AccessibleStates.ReadOnly;
                }
            }

            // The CurveLegend objects are "child" controls in terms of accessibility so 
            // return the number of ChartLengend objects. 
            public override int GetChildCount()
            {  
                return chartControl.Legends.Length;
            }

            // Gets the Accessibility object of the child CurveLegend idetified by index. 
            public override AccessibleObject GetChild(int index)
            {  
                if (index >= 0 && index < chartControl.Legends.Length) {
                    return chartControl.Legends[index].AccessibilityObject;
                }                
                return null;
            }

            // Helper function that is used by the CurveLegend's accessibility object 
            // to navigate between sibiling controls. Specifically, this function is used in 
            // the CurveLegend.CurveLegendAccessibleObject.Navigate function. 
            internal AccessibleObject NavigateFromChild(CurveLegend.CurveLegendAccessibleObject child, 
                                                        AccessibleNavigation navdir) 
            {  
                switch(navdir) {
                    case AccessibleNavigation.Down:
                    case AccessibleNavigation.Next:
                        return GetChild(child.ID + 1);

                    case AccessibleNavigation.Up:
                    case AccessibleNavigation.Previous:
                        return GetChild(child.ID - 1);                        
                }
                return null;
            }

            // Helper function that is used by the CurveLegend's accessibility object 
            // to select a specific CurveLegend control. Specifically, this function is used 
            // in the CurveLegend.CurveLegendAccessibleObject.Select function. 
            internal void SelectChild(CurveLegend.CurveLegendAccessibleObject child, AccessibleSelection selection) 
            {   
                int childID = child.ID;

                // Determine which selection action should occur, based on the 
                // AccessibleSelection value. 
                if ((selection & AccessibleSelection.TakeSelection) != 0) {
                    for(int i = 0; i < chartControl.Legends.Length; i++) {
                        if (i == childID) {
                            chartControl.Legends[i].Selected = true;                        
                        } else {
                            chartControl.Legends[i].Selected = false;
                        }
                    }

                    // AccessibleSelection.AddSelection means that the CurveLegend will be selected. 
                    if ((selection & AccessibleSelection.AddSelection) != 0) {
                        chartControl.Legends[childID].Selected = true;                        
                    }

                    // AccessibleSelection.AddSelection means that the CurveLegend will be unselected. 
                    if ((selection & AccessibleSelection.RemoveSelection) != 0) {
                        chartControl.Legends[childID].Selected = false;                        
                    }
                }            
            }
        }

        // Inner Class that represents a legend for a curve in the chart. 
        public class CurveLegend 
        {
            private string name;
            private ChartControl chart;
            private CurveLegendAccessibleObject accObj;
            private bool selected = true;
            private Point location;

            public CurveLegend(ChartControl chart, string name) 
            {
                this.chart = chart;
                this.name = name;
            }

            // Gets the accessibility object for the curve legend. 
            public AccessibleObject AccessibilityObject
            {
                get {
                    if (accObj == null) {
                        accObj = new CurveLegendAccessibleObject(this);
                    }
                    return accObj;
                }
            }

            // Gets the bounds for the curve legend. 
            public Rectangle Bounds
            {   
                get {
                    return new Rectangle(Location, Size);
                }
            }

            // Gets or sets the location for the curve legend. 
            public Point Location
            {   
                get {
                    return location;
                }
                set {
                    location = value;
                    chart.Invalidate();

                    // Notifies the chart of the location change. This is used for 
                    // the accessibility information. AccessibleEvents.LocationChange 
                    // tells the chart the reason for the notification.

                    chart.AccessibilityNotifyClients(AccessibleEvents.LocationChange, 
                        ((CurveLegendAccessibleObject)AccessibilityObject).ID);
                }
            }            

            // Gets or sets the Name for the curve legend. 
            public string Name
            {   
                get {
                    return name;
                }
                set {
                    if (name != value) 
                    {
                        name = value;
                        chart.Invalidate();

                        // Notifies the chart of the name change. This is used for 
                        // the accessibility information. AccessibleEvents.NameChange 
                        // tells the chart the reason for the notification.

                        chart.AccessibilityNotifyClients(AccessibleEvents.NameChange, 
                            ((CurveLegendAccessibleObject)AccessibilityObject).ID);
                    }
                }
            }

            // Gets or sets the Selected state for the curve legend. 
            public bool Selected
            {   
                get {
                    return selected;
                }
                set {
                    if (selected != value) 
                    {
                        selected = value;
                        chart.Invalidate();

                        // Notifies the chart of the selection value change. This is used for 
                        // the accessibility information. The AccessibleEvents value depends upon 
                        // if the selection is true (AccessibleEvents.SelectionAdd) or  
                        // false (AccessibleEvents.SelectionRemove).
                        chart.AccessibilityNotifyClients(
                            selected ? AccessibleEvents.SelectionAdd : AccessibleEvents.SelectionRemove, 
                            ((CurveLegendAccessibleObject)AccessibilityObject).ID);
                    }
                }
            }

            // Gets the Size for the curve legend. 
            public Size Size
            {   
                get {                    
                    int legendHeight = chart.Font.Height + 4;
                    Graphics g = chart.CreateGraphics();
                    int legendWidth = (int)g.MeasureString(Name, chart.Font).Width + 4;            

                    return new Size(legendWidth, legendHeight);
                }
            }

            // Inner class CurveLegendAccessibleObject represents accessible information  
            // associated with the CurveLegend object. 
            public class CurveLegendAccessibleObject : AccessibleObject
            {
                private CurveLegend curveLegend;

                public CurveLegendAccessibleObject(CurveLegend curveLegend) : base() 
                {
                    this.curveLegend = curveLegend;                    
                }                

                // Private property that helps get the reference to the parent ChartControl. 
                private ChartControlAccessibleObject ChartControl
                {   
                    get {
                        return Parent as ChartControlAccessibleObject;
                    }
                }

                // Internal helper function that returns the ID for this CurveLegend. 
                internal int ID
                {
                    get {
                        for(int i = 0; i < ChartControl.GetChildCount(); i++) {
                            if (ChartControl.GetChild(i) == this) {
                                return i;
                            }
                        }
                        return -1;
                    }
                }

                // Gets the Bounds for the CurveLegend. This is used by accessibility programs. 
                public override Rectangle Bounds
                {
                    get {                        
                        // The bounds is in screen coordinates.
                        Point loc = curveLegend.Location;
                        return new Rectangle(curveLegend.chart.PointToScreen(loc), curveLegend.Size);
                    }
                }

                // Gets or sets the Name for the CurveLegend. This is used by accessibility programs. 
                public override string Name
                {
                    get {
                        return curveLegend.Name;
                    }
                    set {
                        curveLegend.Name = value;                        
                    }
                }

                // Gets the Curve Legend Parent's Accessible object. 
                // This is used by accessibility programs. 
                public override AccessibleObject Parent
                {
                    get {
                        return curveLegend.chart.AccessibilityObject;
                    }
                }

                // Gets the role for the CurveLegend. This is used by accessibility programs. 
                public override AccessibleRole Role 
                {
                    get {
                        return AccessibleRole.StaticText;
                    }
                }

                // Gets the state based on the selection for the CurveLegend.  
                // This is used by accessibility programs. 
                public override AccessibleStates State 
                {
                    get {
                        AccessibleStates state = AccessibleStates.Selectable;
                        if (curveLegend.Selected) 
                        {
                            state |= AccessibleStates.Selected;
                        }
                        return state;
                    }
                }

                // Navigates through siblings of this CurveLegend. This is used by accessibility programs. 
                public override AccessibleObject Navigate(AccessibleNavigation navdir) 
                {
                    // Uses the internal NavigateFromChild helper function that exists 
                    // on ChartControlAccessibleObject. 
                    return ChartControl.NavigateFromChild(this, navdir);
                }

                // Selects or unselects this CurveLegend. This is used by accessibility programs. 
                public override void Select(AccessibleSelection selection) 
                {
                    // Uses the internal SelectChild helper function that exists 
                    // on ChartControlAccessibleObject.
                    ChartControl.SelectChild(this, selection);
                }
            }
        }
    }
}

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, 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.

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

Show:
© 2014 Microsoft