Exportar (0) Imprimir
Expandir todo

AccessibleObject (Clase)

Proporciona información utilizada por las aplicaciones de accesibilidad para ajustar la interfaz de usuario de una aplicación a los usuarios discapacitados.

Espacio de nombres: System.Windows.Forms
Ensamblado: System.Windows.Forms (en system.windows.forms.dll)

[ComVisibleAttribute(true)] 
public class AccessibleObject : StandardOleMarshalObject, IReflect, IAccessible
/** @attribute ComVisibleAttribute(true) */ 
public class AccessibleObject extends StandardOleMarshalObject implements IReflect, IAccessible
ComVisibleAttribute(true) 
public class AccessibleObject extends StandardOleMarshalObject implements IReflect, IAccessible
No aplicable.

Las aplicaciones de accesibilidad pueden ajustar características de la aplicación para mejorar las prestaciones que ofrece a los usuarios con discapacidades.

Para usuarios con limitaciones visuales, se pueden ajustar las características del software y del sistema operativo para que cubran sus necesidades. Por ejemplo, el texto y las imágenes se pueden agrandar y también representar con contraste. Además, se puede mejorar la accesibilidad de los daltónicos mediante el uso apropiado de los colores. Los usuarios con limitaciones visuales graves pueden tener acceso a los equipos mediante soportes de revisión que transfieren el texto en pantalla a voz o adaptadores de Braille dinámicos y actualizables.

Para usuarios con problemas auditivos, se pueden diseñar programas que utilicen guías visuales, como una barra de herramientas que emita destellos, o ver los mensajes de voz en forma de texto. Por ejemplo, cuando se activa la característica SoundSentry, una opción de accesibilidad del Panel de control, se genera un aviso visual cada vez que el sistema emite un sonido de alarma.

Para usuarios con limitaciones físicas, se pueden diseñar controles que adapten o eliminen el uso del teclado y del mouse (ratón) para mejorar así la accesibilidad del equipo. El Panel de control le proporcionará ayuda. Por ejemplo, una de las alternativas es utilizar el teclado numérico en lugar del mouse para los desplazamientos. Otra opción, denominada StickyKeys, permite a los usuarios que no pueden mantener presionadas dos o más teclas a la vez (como CTRL+P) obtener el mismo resultado introduciendo las teclas de una en una.

Para usuarios con limitaciones de aprendizaje, se pueden diseñar programas de software que se adapten mejor a sus necesidades. Por ejemplo, el uso de secuencias llamativas o de guía, presentaciones sencillas, menos palabras y un nivel de lectura enfocado hacia los estándares de enseñanza primaria puede beneficiar a estos usuarios.

Para usuarios con trastornos que deriven en ataques, se pueden diseñar programas de software que eliminen los patrones que puedan provocar dichos ataques.

Para obtener más información sobre la accesibilidad, incluida información sobre aplicaciones de accesibilidad, consulte la documentación de accesibilidad de Microsoft en la MSDN Library o en el sitio Web de Microsoft.

NotaNota:

Para utilizar el objeto AccessibleObject, debe agregar una referencia al ensamblado Accessibility instalado con .NET Framework. Windows Forms sólo admite Active Accessibility 2.0.

Notas para los herederos: Al heredar de esta clase, puede reemplazar todos los miembros.

En el siguiente ejemplo de código se muestra la creación de un control de gráfico con reconocimiento de accesibilidad mediante las clases AccessibleObject y Control.ControlAccessibleObject con el fin de exponer información accesible. El control dibuja dos curvas acompañadas de una leyenda. La clase ChartControlAccessibleObject, que se deriva de ControlAccessibleObject, se utiliza en el método CreateAccessibilityInstance a fin de proporcionar información personalizada accesible para el control de gráfico. Dado que la leyenda del gráfico no es en realidad un control basado en Control, sino que la dibuja el control de gráfico, no contiene ninguna información integrada accesible. Debido a esto, la clase ChartControlAccessibleObject reemplaza el método GetChild para devolver CurveLegendAccessibleObject, que representa la información accesible de cada parte de la leyenda. Cuando este control se utiliza en una aplicación con reconocimiento de accesibilidad, el control puede proporcionar la información accesible que sea necesaria.

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

package ChartControl;

import System.*;
import System.Drawing.*;
import System.Windows.Forms.*;

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

    /** @attribute STAThread()
     */
    public static void main(String[] args)
    {
        Application.Run(new Form1());
    } //main

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

        this.chart1.set_Location(new System.Drawing.Point(47, 16));
        this.chart1.set_Size(new System.Drawing.Size(600, 400));
        this.get_Controls().Add(this.chart1);
    } //Form1
} //Form1

// Declare a chart control that demonstrates accessibility in Windows Forms.
public class ChartControl extends 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.set_BackColor(System.Drawing.Color.get_White());
        this.set_Name("ChartControl");
        this.add_Click(new System.EventHandler(this.ChartControl_Click));
        this.add_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.set_Location(new Point(20, 30));
        legend2 = new CurveLegend(this, "B");
        legend2.set_Location(new Point(20, 50));
    } //ChartControl

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

    protected void OnPaint(PaintEventArgs e)
    {
        // The ChartControl draws the chart in the OnPaint override.
        super.OnPaint(e);
        Rectangle bounds = this.get_ClientRectangle();
        int border = 5;
        // Draws the legends first.
        StringFormat format = new StringFormat();
        format.set_Alignment(StringAlignment.Center);
        format.set_LineAlignment(StringAlignment.Center);

        if (legend1 != null) {
            if (legend1.get_Selected()) {
                e.get_Graphics().FillRectangle(new SolidBrush(Color.get_Blue()),
                    legend1.get_Bounds());
            }
            else {
                e.get_Graphics().DrawRectangle(Pens.get_Blue(), 
                    legend1.get_Bounds());
            }
            e.get_Graphics().DrawString(legend1.get_Name(), this.get_Font(), 
                Brushes.get_Black(), 
                RectangleF.op_Implicit(legend1.get_Bounds()), format);
        }
        if (legend2 != null) {
            if (legend2.get_Selected()) {
                e.get_Graphics().FillRectangle(new SolidBrush(Color.get_Red()), 
                    legend2.get_Bounds());
            }
            else {
                e.get_Graphics().DrawRectangle(Pens.get_Red(),
                    legend2.get_Bounds());
            }
            e.get_Graphics().DrawString(legend2.get_Name(), this.get_Font(),
                Brushes.get_Black(), 
                RectangleF.op_Implicit(legend2.get_Bounds()), format);
        }

        // Charts out the actual curves that represent data in the Chart.
        bounds.Inflate(-border, -border);
        Point curve1[] = new Point[] { new Point(bounds.get_Left(), 
            bounds.get_Bottom()), 
            new Point(bounds.get_Left() + bounds.get_Width() / 3,
            bounds.get_Top() + bounds.get_Height() / 5), 
            new Point(bounds.get_Right() - bounds.get_Width() / 3, 
            (bounds.get_Top() + bounds.get_Bottom()) / 2), 
            new Point(bounds.get_Right(), bounds.get_Top()) };

        Point curve2[] = new Point[] { new Point(bounds.get_Left(), 
            bounds.get_Bottom() - bounds.get_Height() / 3), 
            new Point(bounds.get_Left() + bounds.get_Width() / 3, 
            bounds.get_Top() + bounds.get_Height() / 5), 
            new Point(bounds.get_Right() - bounds.get_Width() / 3, 
            (bounds.get_Top() + bounds.get_Bottom()) / 2), 
            new Point(bounds.get_Right(), 
            bounds.get_Top() + bounds.get_Height() / 2) };

        // Draws the actual curve only if it is selected.
        if (legend1.get_Selected()) {
            e.get_Graphics().DrawCurve(Pens.get_Blue(), curve1);
        }
        if (legend2.get_Selected()) {
            e.get_Graphics().DrawCurve(Pens.get_Red(), curve2);
        }
        e.get_Graphics().DrawRectangle(Pens.get_Blue(), bounds);
    } //OnPaint

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

    // 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.get_MousePosition());
        if (legend1.get_Bounds().Contains(pt)) {
            legend1.set_Selected(!(legend1.get_Selected()));
        }
        else {
            if (legend2.get_Bounds().Contains(pt)) {
                legend2.set_Selected(!(legend2.get_Selected()));
            }
        }
    } //ChartControl_Click

    // Gets an array of CurveLengends used in the Chart.
    /** @property 
     */
    public CurveLegend[] get_Legends()
    {
        return new CurveLegend[] { legend1, legend2 };
    } //get_Legends

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

        public ChartControlAccessibleObject(ChartControl ctrl)
        {
            super(ctrl);
            chartControl = ctrl;
        } //ChartControlAccessibleObject

        // Gets the role for the Chart. This is used by accessibility programs.
        /** @property 
         */
        public AccessibleRole get_Role()
        {
            return AccessibleRole.Chart;
        } //get_Role

        // Gets the state for the Chart. This is used by accessibility programs.
        /** @property 
         */
        public AccessibleStates get_State()
        {
            return AccessibleStates.ReadOnly;
        } //get_State

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

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

        // 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.
        AccessibleObject NavigateFromChild(
            CurveLegend.CurveLegendAccessibleObject child, 
            AccessibleNavigation navDir)
        {
            if (navDir.Equals(AccessibleNavigation.Down) 
                || navDir.Equals(AccessibleNavigation.Next)) {
                return GetChild(child.get_ID() + 1);
            }
            else {
                if (navDir.Equals(AccessibleNavigation.Up) 
                    || navDir.Equals(AccessibleNavigation.Previous)) {
                    return GetChild(child.get_ID() - 1);
                }
            }
            return null;
        } //NavigateFromChild

        // 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.
        public void SelectChild(CurveLegend.CurveLegendAccessibleObject child, 
            AccessibleSelection selection)
        {
            int childID = child.get_ID();

            // Determine which selection action should occur, based on the
            // AccessibleSelection value.
            if (Convert.ToInt32(selection & AccessibleSelection.TakeSelection)
                != 0) {
                for (int i = 0; i < chartControl.get_Legends().get_Length(); 
                    i++) {
                    if (i == childID) {
                        ((CurveLegend)chartControl.get_Legends().get_Item(i)).
                            set_Selected(true);
                    }
                    else {
                        ((CurveLegend)chartControl.get_Legends().get_Item(i)).
                            set_Selected(false);
                    }
                }

                // AccessibleSelection.AddSelection means that the CurveLegend 
                // will be selected.
                if (Convert.ToInt32(selection & AccessibleSelection.AddSelection)
                    != 0) {
                    ((CurveLegend)chartControl.get_Legends().get_Item(childID)).
                        set_Selected(true);
                }

                // AccessibleSelection.AddSelection means that the CurveLegend 
                // will be unselected.
                if (Convert.ToInt32(selection & 
                    AccessibleSelection.RemoveSelection) != 0) {
                    ((CurveLegend)chartControl.get_Legends().get_Item(childID)).
                        set_Selected(false);
                }
            }
        } //SelectChild
    } //ChartControlAccessibleObject

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

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

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

        // Gets the bounds for the curve legend.
        /** @property 
         */
        public Rectangle get_Bounds()
        {
            return new Rectangle(get_Location(), get_Size());
        } //get_Bounds

        // Gets or sets the location for the curve legend.
        /** @property 
         */
        public Point get_Location()
        {
            return location;
        } //get_Location

        /** @property 
         */
        public void set_Location(Point value)
        {
            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)get_AccessibilityObject()).
                get_ID());
        } //set_Location

        // Gets or sets the Name for the curve legend.
        /** @property 
         */
        public String get_Name()
        {
            return name;
        } //get_Name

        /** @property 
         */
        public void set_Name(String value)
        {
            if (!name.Equals(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)get_AccessibilityObject()).
                    get_ID());
            }
        } //set_Name

        // Gets or sets the Selected state for the curve legend.
        /** @property 
         */
        public boolean get_Selected()
        {
            return selected;
        } //get_Selected

        /** @property 
         */
        public void set_Selected(boolean value)
        {
            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)get_AccessibilityObject()).
                    get_ID());
            }
        } //set_Selected

        // Gets the Size for the curve legend.
        /** @property 
         */
        public Size get_Size()
        {
            int legendHeight = chart.get_Font().get_Height() + 4;
            Graphics g = chart.CreateGraphics();
            int legendWidth = (int)(g.MeasureString(get_Name(), 
                chart.get_Font()).get_Width()) + 4;

            return new Size(legendWidth, legendHeight);
        } //get_Size

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

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

            // Private property that helps get the reference to the parent 
            // ChartControl.
            /** @property 
             */
            private ChartControlAccessibleObject get_ChartControl()
            {
                return (ChartControlAccessibleObject)get_Parent();
            } //get_ChartControl

            // Internal helper function that returns the ID for this CurveLegend.
            /** @property 
             */
            int get_ID()
            {
                for (int i = 0; i < get_ChartControl().GetChildCount(); i++) {
                    if (get_ChartControl().GetChild(i).Equals(this)) {
                        return i;
                    }
                }
                return -1;
            } //get_ID

            // Gets the Bounds for the CurveLegend. 
            // This is used by accessibility programs.
            /** @property 
             */
            public Rectangle get_Bounds()
            {
                // The bounds is in screen coordinates.
                Point loc = curveLegend.get_Location();
                return new Rectangle(curveLegend.chart.PointToScreen(loc),
                    curveLegend.get_Size());
            } //get_Bounds

            // Gets or sets the Name for the CurveLegend. 
            // This is used by accessibility programs.
            /** @property 
             */
            public String get_Name()
            {
                return curveLegend.get_Name();
            } //get_Name

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

            // Gets the Curve Legend Parent's Accessible object.
            // This is used by accessibility programs.
            /** @property 
             */
            public AccessibleObject get_Parent()
            {
                return curveLegend.chart.get_AccessibilityObject();
            } //get_Parent

            // Gets the role for the CurveLegend. 
            // This is used by accessibility programs.
            /** @property 
             */
            public AccessibleRole get_Role()
            {
                return AccessibleRole.StaticText;
            } //get_Role

            // Gets the state based on the selection for the CurveLegend. 
            // This is used by accessibility programs.
            /** @property 
             */
            public AccessibleStates get_State()
            {
                AccessibleStates state = AccessibleStates.Selectable;
                if (curveLegend.get_Selected()) {
                    state = state | AccessibleStates.Selected;
                }
                return state;
            } //get_State

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

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

Los miembros estáticos públicos (Shared en Visual Basic) de este tipo son seguros para la ejecución de subprocesos. No se garantiza que los miembros de instancias sean seguros para la ejecución de subprocesos.

Windows 98, Windows 2000 Service Pack 4, Windows CE, Windows Millennium, Windows Mobile para Pocket PC, Windows Mobile para Smartphone, Windows Server 2003, Windows XP Media Center, Windows XP Professional x64, Windows XP SP2, Windows XP Starter

Microsoft .NET Framework 3.0 es compatible con Windows Vista, Microsoft Windows XP SP2 y Windows Server 2003 SP1.

.NET Framework

Compatible con: 3.0, 2.0, 1.1, 1.0
Mostrar:
© 2014 Microsoft