다음을 통해 공유


AccessibleObject 클래스

내게 필요한 옵션 지원 응용 프로그램이 시각 장애인을 위해 응용 프로그램 UI(사용자 인터페이스)를 조정하는 데 사용하는 정보를 제공합니다.

네임스페이스: System.Windows.Forms
어셈블리: System.Windows.Forms(system.windows.forms.dll)

구문

‘선언
<ComVisibleAttribute(True)> _
Public Class AccessibleObject
    Inherits StandardOleMarshalObject
    Implements IReflect, IAccessible
‘사용 방법
Dim instance As AccessibleObject
[ComVisibleAttribute(true)] 
public class AccessibleObject : StandardOleMarshalObject, IReflect, IAccessible
[ComVisibleAttribute(true)] 
public ref class AccessibleObject : public StandardOleMarshalObject, IReflect, IAccessible
/** @attribute ComVisibleAttribute(true) */ 
public class AccessibleObject extends StandardOleMarshalObject implements IReflect, IAccessible
ComVisibleAttribute(true) 
public class AccessibleObject extends StandardOleMarshalObject implements IReflect, IAccessible

설명

내게 필요한 옵션 지원 응용 프로그램은 장애인의 사용 효율을 향상시키도록 응용 프로그램의 기능을 조정할 수 있습니다.

시작 장애인을 위해 소프트웨어와 운영 체제의 기능을 조정할 수 있습니다. 예를 들어, 텍스트와 이미지를 확대하고 대비를 사용하여 텍스트와 이미지를 렌더링할 수 있습니다. 또한, 색맹 사용자를 위해 색을 적절히 조정할 수 있습니다. 시각 장애가 심한 사용자의 경우 화면 텍스트를 음성이나, 재생 가능한 동적 점자로 변환하는 화면 검토 기능으로 컴퓨터를 사용할 수 있습니다.

청각 장애인을 위해 깜박이는 도구 모음과 같은 시각적 효과를 사용하는 프로그램을 만들거나 음성 메시지를 텍스트로 표시할 수 있습니다. 예를 들어, 제어판의 내게 필요한 옵션인 SoundSentry 기능을 사용하면 시스템에서 경고음이 발생할 때마다 시각적 경고가 표시됩니다.

지체 장애인을 위해 키보드 및 마우스 사용을 없애거나 사용 방식을 간편화하는 컨트롤을 개발하여 컴퓨터 액세스 가능성을 개선할 수 있습니다. 이 작업을 위해서는 제어판을 사용합니다. 예를 들어, 마우스를 사용하여 탐색하는 대신 숫자 키패드를 사용할 수 있습니다. StickyKeys라는 옵션을 사용하면 Ctrl+P와 같은 두 개 이상의 키를 동시에 누를 수 없는 사용자도 한 번에 하나의 키를 입력하여 동일한 결과를 얻을 수 있습니다.

인지도와 언어 이해력이 부족한 사용자를 위해서도 보다 편리한 컴퓨터 사용을 위한 소프트웨어를 만들 수 있습니다. 예를 들어, 이해하기 쉽게 간단히 화면을 표시하고, 글자 수를 줄이고, 초등학교 수준의 문장을 사용하면 이러한 사용자도 쉽게 컴퓨터를 사용할 수 있습니다.

발작 이상 증세가 있는 사용자를 위해 발작 요인을 없앨 수 있는 소프트웨어를 만들 수 있습니다.

내게 필요한 옵션 지원 응용 프로그램 관련 정보를 포함하여 내게 필요한 옵션에 대한 자세한 내용은 MSDN library나 Microsoft 웹 사이트에 있는 Microsoft Accessibility 관련 문서를 참조하십시오.

참고

AccessibleObject를 사용하려면 .NET Framework와 함께 설치된 Accessibility 어셈블리에 참조를 추가해야 합니다.

상속자 참고 사항 이 클래스에서 상속하면 모든 멤버를 재정의할 수 있습니다.

예제

다음 코드 예제에서는 액세스할 수 있는 정보를 노출하는 AccessibleObjectControl.ControlAccessibleObject 클래스를 사용하여 액세스 가능성 구분 차트 컨트롤을 작성하는 방법을 보여 줍니다. 이 컨트롤은 범례를 따라 두 곡선을 그립니다. ControlAccessibleObject에서 파생되는 ChartControlAccessibleObject 클래스는 CreateAccessibilityInstance 메서드에서 차트 컨트롤에 대한 사용자 지정 액세스 가능 정보를 제공하는 데 사용됩니다. 차트 범례는 실제 Control 기반 컨트롤은 아니지만 차트 컨트롤에 의해 그려지며 액세스할 수 있는 내장 정보를 포함하고 있지 않습니다. 이로 인해 ChartControlAccessibleObject 클래스가 GetChild 메서드를 재정의하여 각 범례 부분에 대한 액세스 가능 정보를 나타내는 CurveLegendAccessibleObject를 반환합니다. 액세스할 수 있는 응용 프로그램에서 이 컨트롤을 사용할 때 이 컨트롤은 필요한 액세스 가능 정보를 제공할 수 있습니다.

Option Explicit

Imports System
Imports System.Drawing
Imports System.Windows.Forms

Namespace ChartControlNameSpace
    
    Public Class Form1 
        Inherits System.Windows.Forms.Form

        ' Test out the Chart Control.
        Private chart1 As ChartControl

        <System.STAThread()> _
        Public Shared Sub Main()
            System.Windows.Forms.Application.Run(New Form1())
        End Sub 'Main

        Public Sub New() 
            ' Create a chart control and add it to the form.
            Me.chart1 = New ChartControl()
            Me.ClientSize = New System.Drawing.Size(920, 566)

            Me.chart1.Location = New System.Drawing.Point(47, 16)
            Me.chart1.Size = New System.Drawing.Size(600, 400)

            Me.Controls.Add(Me.chart1)
        End Sub
    End Class

    ' Declares a chart control that demonstrates Accessibility in Windows Forms.
    Public Class ChartControl
        Inherits System.Windows.Forms.UserControl

        Private legend1 As CurveLegend
        Private legend2 As CurveLegend
        
        Public Sub New()
            ' The ChartControl draws the chart in the OnPaint override.
            SetStyle(ControlStyles.ResizeRedraw, True)
            SetStyle(ControlStyles.DoubleBuffer, True)
            SetStyle(ControlStyles.AllPaintingInWmPaint, True)
            
            Me.BackColor = System.Drawing.Color.White
            Me.Name = "ChartControl"

            ' The CurveLengend is not Control-based, it just
            ' represent the parts of the legend.
            legend1 = New CurveLegend(Me, "A")
            legend1.Location = New Point(20, 30)
            legend2 = New CurveLegend(Me, "B")
            legend2.Location = New Point(20, 50)
        End Sub 'New
              
        ' Overridden to return the custom AccessibleObject 
        ' for the entire chart.
        Protected Overrides Function CreateAccessibilityInstance() As AccessibleObject
            Return New ChartControlAccessibleObject(Me)
        End Function 

        Protected Overrides Sub OnPaint(e As PaintEventArgs)
            ' The ChartControl draws the chart in the OnPaint override.
            MyBase.OnPaint(e)
            
            Dim bounds As Rectangle = Me.ClientRectangle
            Dim border As Integer = 5
            
            ' Draw the legends first.
            Dim format As New StringFormat()
            format.Alignment = StringAlignment.Center
            format.LineAlignment = StringAlignment.Center
            
            If Not (legend1 Is Nothing) Then
                If legend1.Selected Then
                    e.Graphics.FillRectangle(New SolidBrush(Color.Blue), legend1.Bounds)
                Else
                    e.Graphics.DrawRectangle(Pens.Blue, legend1.Bounds)
                End If
                e.Graphics.DrawString(legend1.Name, Me.Font, Brushes.Black, RectangleF.op_Implicit(legend1.Bounds), format)
            End If
            If Not (legend2 Is Nothing) Then
                If legend2.Selected Then
                    e.Graphics.FillRectangle(New SolidBrush(Color.Red), legend2.Bounds)
                Else
                    e.Graphics.DrawRectangle(Pens.Red, legend2.Bounds)
                End If
                e.Graphics.DrawString(legend2.Name, Me.Font, Brushes.Black, RectangleF.op_Implicit(legend2.Bounds), format)
            End If
            
            ' Chart out the actual curves that represent data in the Chart.
            bounds.Inflate(-border, -border)
            Dim curve1() As 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)}

            Dim curve2() As 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)}
            
            ' Draw the actual curve only if it is selected.
            If legend1.Selected Then
                e.Graphics.DrawCurve(Pens.Blue, curve1)
            End If
            If legend2.Selected Then
                e.Graphics.DrawCurve(Pens.Red, curve2)
            End If 
            e.Graphics.DrawRectangle(Pens.Blue, bounds)
        End Sub 'OnPaint
        
        ' Handle the QueryAccessibilityHelp event.
        Private Sub ChartControl_QueryAccessibilityHelp(sender As Object, _
                           e As System.Windows.Forms.QueryAccessibilityHelpEventArgs) Handles MyBase.QueryAccessibilityHelp
            e.HelpString = "Displays chart data"
        End Sub 

        ' Handle the Click event for the chart. 
        ' Toggle the selection of whatever legend was clicked.     
        Private Sub ChartControl_Click(sender As Object, e As System.EventArgs) Handles MyBase.Click

            Dim pt As Point = Me.PointToClient(Control.MousePosition)
            If legend1.Bounds.Contains(pt) Then
                legend1.Selected = Not legend1.Selected
            Else
                If legend2.Bounds.Contains(pt) Then
                    legend2.Selected = Not legend2.Selected
                End If
            End If
        End Sub 'ChartControl_Click

        ' Get an array of the CurveLengends used in the Chart.
        Public ReadOnly Property Legends() As CurveLegend()
            Get
                Return New CurveLegend() {legend1, legend2}
            End Get
        End Property
        
        Protected Sub ExposeAccessibilityNotifyClients(ByVal accEvent As AccessibleEvents, ByVal childID As Integer)
            AccessibilityNotifyClients(accEvent, childID) 
        End Sub

        ' Inner Class ChartControlAccessibleObject represents accessible information 
        ' associated with the ChartControl.
        ' The ChartControlAccessibleObject is returned in the         ' ChartControl.CreateAccessibilityInstance override.
        Public Class ChartControlAccessibleObject
            Inherits Control.ControlAccessibleObject

            Private chartControl As ChartControl
            
            Public Sub New(ctrl As ChartControl)
                MyBase.New(ctrl)
                chartControl = ctrl
            End Sub 'New
            
            ' Get the role for the Chart. This is used by accessibility programs.            
            Public Overrides ReadOnly Property Role() As AccessibleRole
                Get
                    Return System.Windows.Forms.AccessibleRole.Chart
                End Get
            End Property
            
            ' Get the state for the Chart. This is used by accessibility programs.            
            Public Overrides ReadOnly Property State() As AccessibleStates
                Get
                    Return AccessibleStates.ReadOnly
                End Get
            End Property                        
            
            ' The CurveLegend objects are "child" controls in terms of accessibility so 
            ' return the number of ChartLengend objects.            
            Public Overrides Function GetChildCount() As Integer
                Return chartControl.Legends.Length
            End Function 
            
            ' Get the Accessibility object of the child CurveLegend idetified by index.
            Public Overrides Function GetChild(index As Integer) As AccessibleObject
                If index >= 0 And index < chartControl.Legends.Length Then
                    Return chartControl.Legends(index).AccessibilityObject
                End If
                Return Nothing
            End Function 
            
            ' 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.
            Friend Function NavigateFromChild(child As CurveLegend.CurveLegendAccessibleObject, _
                                            navdir As AccessibleNavigation) As AccessibleObject
                Select Case navdir
                    Case AccessibleNavigation.Down, AccessibleNavigation.Next
                            Return GetChild(child.ID + 1)
                    
                    Case AccessibleNavigation.Up, AccessibleNavigation.Previous
                            Return GetChild(child.ID - 1)
                End Select
                Return Nothing
            End Function            

            ' 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.            
            Friend Sub SelectChild(child As CurveLegend.CurveLegendAccessibleObject, selection As AccessibleSelection)
                Dim childID As Integer = child.ID
                
                ' Determine which selection action should occur, based on the
                ' AccessibleSelection value.
                If (selection And AccessibleSelection.TakeSelection) <> 0 Then
                    Dim i As Integer
                    For i = 0 To chartControl.Legends.Length - 1
                        If i = childID Then
                            chartControl.Legends(i).Selected = True
                        Else
                            chartControl.Legends(i).Selected = False
                        End If
                    Next i
                    
                    ' AccessibleSelection.AddSelection means that the CurveLegend will be selected.
                    If (selection And AccessibleSelection.AddSelection) <> 0 Then
                        chartControl.Legends(childID).Selected = True
                    End If

                    ' AccessibleSelection.AddSelection means that the CurveLegend will be unselected.                    
                    If (selection And AccessibleSelection.RemoveSelection) <> 0 Then
                        chartControl.Legends(childID).Selected = False
                    End If
                End If
            End Sub 'SelectChild
        End Class 'ChartControlAccessibleObject

        ' Inner Class that represents a legend for a curve in the chart.
        Public Class CurveLegend
            Private m_name As String
            Private chart As ChartControl
            Private accObj As CurveLegendAccessibleObject
            Private m_selected As Boolean = True
            Private m_location As Point
            
            Public Sub New(chart As ChartControl, name As String)
                Me.chart = chart
                Me.m_name = name
            End Sub 'New

            ' Gets the accessibility object for the curve legend.            
            Public ReadOnly Property AccessibilityObject() As AccessibleObject
                Get
                    If accObj Is Nothing Then
                        accObj = New CurveLegendAccessibleObject(Me)
                    End If
                    Return accObj
                End Get
            End Property
            
            ' Gets the bounds for the curve legend.            
            Public ReadOnly Property Bounds() As Rectangle
                Get
                    Return New Rectangle(Location, Size)
                End Get
            End Property

            ' Gets or sets the location for the curve legend.            
            Public Property Location() As Point
                Get
                    Return m_location
                End Get
                Set
                    m_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.ExposeAccessibilityNotifyClients(AccessibleEvents.LocationChange, _
                            CType(AccessibilityObject, CurveLegendAccessibleObject).ID)
                End Set
            End Property
            
            ' Gets or sets the Name for the curve legend.            
            Public Property Name() As String
                Get
                    Return m_name
                End Get
                Set
                    If m_name <> value Then
                        m_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.ExposeAccessibilityNotifyClients(AccessibleEvents.NameChange, _
                                CType(AccessibilityObject, CurveLegendAccessibleObject).ID)
                    End If
                End Set
            End Property
            
            ' Gets or sets the Selected state for the curve legend.            
            Public Property Selected() As Boolean
                Get
                    Return m_selected
                End Get
                Set
                    If m_selected <> value Then
                        m_selected = value
                        chart.Invalidate()

                        ' Notifies the chart of the selection value change. This is used for
                        ' the accessibility information. The AccessibleEvents value varies
                        ' on whether the selection is true (AccessibleEvents.SelectionAdd) or 
                        ' false (AccessibleEvents.SelectionRemove). 
                        If m_selected Then
                            chart.ExposeAccessibilityNotifyClients(AccessibleEvents.SelectionAdd, _
                                    CType(AccessibilityObject, CurveLegendAccessibleObject).ID) 
                        Else
                            chart.ExposeAccessibilityNotifyClients(AccessibleEvents.SelectionRemove, _
                                    CType(AccessibilityObject, CurveLegendAccessibleObject).ID) 
                        End If
                    End If
                End Set
            End Property
            
            ' Gets the Size for the curve legend.            
            Public ReadOnly Property Size() As Size
                Get
                    Dim legendHeight As Integer = chart.Font.Height + 4
                    Dim g As Graphics = chart.CreateGraphics()
                    Dim legendWidth As Integer = CInt(g.MeasureString(Name, chart.Font).Width) + 4
                    
                    Return New Size(legendWidth, legendHeight)
                End Get
            End Property
            
            
            ' Inner class CurveLegendAccessibleObject represents accessible information 
            ' associated with the CurveLegend object.
            Public Class CurveLegendAccessibleObject
                Inherits AccessibleObject

                Private curveLegend As CurveLegend
                
                Public Sub New(curveLegend As CurveLegend)
                    Me.curveLegend = curveLegend
                End Sub 'New
                
                ' Private property that helps get the reference to the parent ChartControl.                
                Private ReadOnly Property ChartControl() As ChartControlAccessibleObject
                    Get
                        Return CType(Parent, ChartControlAccessibleObject)
                    End Get
                End Property

                ' Friend helper function that returns the ID for this CurveLegend.                
                Friend ReadOnly Property ID() As Integer
                    Get
                        Dim i As Integer
                        For i = 0 To (ChartControl.GetChildCount()) - 1
                            If ChartControl.GetChild(i) Is Me Then
                                Return i
                            End If
                        Next i
                        Return - 1
                    End Get
                End Property
                
                ' Gets the Bounds for the CurveLegend. This is used by accessibility programs.
                Public Overrides ReadOnly Property Bounds() As Rectangle
                    Get
                        ' The bounds is in screen coordinates.
                        Dim loc As Point = curveLegend.Location
                        Return New Rectangle(curveLegend.chart.PointToScreen(loc), curveLegend.Size)
                    End Get
                End Property

                ' Gets or sets the Name for the CurveLegend. This is used by accessibility programs.                
                Public Overrides Property Name() As String
                    Get
                        Return curveLegend.Name
                    End Get
                    Set
                        curveLegend.Name = value
                    End Set
                End Property
                
                ' Gets the Curve Legend Parent's Accessible object.
                ' This is used by accessibility programs.                
                Public Overrides ReadOnly Property Parent() As AccessibleObject
                    Get
                        Return curveLegend.chart.AccessibilityObject
                    End Get
                End Property
                
                ' Gets the role for the CurveLegend. This is used by accessibility programs.                
                Public Overrides ReadOnly Property Role() As AccessibleRole
                    Get
                        Return System.Windows.Forms.AccessibleRole.StaticText
                    End Get
                End Property

                ' Gets the state based on the selection for the CurveLegend. 
                ' This is used by accessibility programs.                
                Public Overrides ReadOnly Property State() As AccessibleStates
                    Get
                        Dim stateTemp As AccessibleStates = AccessibleStates.Selectable
                        If curveLegend.Selected Then
                            stateTemp = stateTemp Or AccessibleStates.Selected
                        End If
                        Return stateTemp
                    End Get
                End Property
                
                ' Navigates through siblings of this CurveLegend. This is used by accessibility programs.                
                Public Overrides Function Navigate(navdir As AccessibleNavigation) As AccessibleObject
                    ' Use the Friend NavigateFromChild helper function that exists
                    ' on ChartControlAccessibleObject.
                    Return ChartControl.NavigateFromChild(Me, navdir)
                End Function
                
                ' Selects or unselects this CurveLegend. This is used by accessibility programs.
                Public Overrides Sub [Select](selection As AccessibleSelection)

                    ' Use the internal SelectChild helper function that exists
                    ' on ChartControlAccessibleObject.
                    ChartControl.SelectChild(Me, selection)
                End Sub

            End Class 'CurveLegendAccessibleObject

        End Class 'CurveLegend

    End Class 'ChartControl

End Namespace 'ChartControlNameSpace
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);
                }
            }
        }
    }
}
#using <Accessibility.dll>
#using <System.dll>
#using <System.Windows.Forms.dll>
#using <System.Drawing.dll>

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

// Declare a chart control that demonstrates accessibility in Windows Forms.
public ref class ChartControl: public System::Windows::Forms::UserControl
{
public:
   ref class ChartControlAccessibleObject;

   // forward declaration
   // Inner Class that represents a legend for a curve in the chart.
   ref class CurveLegend
   {

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

      public:
         CurveLegendAccessibleObject( CurveLegend^ curveLegend )
            : AccessibleObject()
         {
            this->curveLegend = curveLegend;
         }


      private:

         property ChartControlAccessibleObject^ ChartControl 
         {

            // Private property that helps get the reference to the parent ChartControl.
            ChartControlAccessibleObject^ get()
            {
               return dynamic_cast<ChartControlAccessibleObject^>(Parent);
            }

         }

      internal:

         property int ID 
         {

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

               }
               return  -1;
            }

         }

      public:

         property Rectangle Bounds 
         {

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

         }

         property String^ Name 
         {

            // Gets or sets the Name for the CurveLegend. This is used by accessibility programs.
            virtual String^ get() override
            {
               return curveLegend->Name;
            }

            virtual void set( String^ value ) override
            {
               curveLegend->Name = value;
            }

         }

         property AccessibleObject^ Parent 
         {

            // Gets the Curve Legend Parent's Accessible object.
            // This is used by accessibility programs.
            virtual AccessibleObject^ get() override
            {
               return curveLegend->chart->AccessibilityObject;
            }

         }

         property System::Windows::Forms::AccessibleRole Role 
         {

            // Gets the role for the CurveLegend. This is used by accessibility programs.
            virtual System::Windows::Forms::AccessibleRole get() override
            {
               return ::AccessibleRole::StaticText;
            }

         }

         property AccessibleStates State 
         {

            // Gets the state based on the selection for the CurveLegend.
            // This is used by accessibility programs.
            virtual AccessibleStates get() override
            {
               AccessibleStates state = AccessibleStates::Selectable;
               if ( curveLegend->Selected )
               {
                  state = static_cast<AccessibleStates>(state | AccessibleStates::Selected);
               }

               return state;
            }

         }

         // Navigates through siblings of this CurveLegend. This is used by accessibility programs.
         virtual AccessibleObject^ Navigate( AccessibleNavigation navdir ) override
         {
            
            // 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.
         virtual void Select( AccessibleSelection selection ) override
         {
            
            // Uses the internal SelectChild helper function that exists
            // on ChartControlAccessibleObject.
            ChartControl->SelectChild( this, selection );
         }

      };


   private:

      // class CurveLgendAccessibleObject
      String^ name;
      ChartControl^ chart;
      CurveLegendAccessibleObject^ accObj;
      bool selected;
      Point location;

   public:
      CurveLegend( ChartControl^ chart, String^ name )
      {
         this->chart = chart;
         this->name = name;
         selected = true;
      }


      property AccessibleObject^ AccessibilityObject 
      {

         // Gets the accessibility object for the curve legend.
         AccessibleObject^ get()
         {
            if ( accObj == nullptr )
            {
               accObj = gcnew CurveLegendAccessibleObject( this );
            }

            return accObj;
         }

      }

      property Rectangle Bounds 
      {

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

      }

      property Point Location 
      {

         // Gets or sets the location for the curve legend.
         Point get()
         {
            return location;
         }

         void set( 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, (dynamic_cast<CurveLegendAccessibleObject^>(AccessibilityObject))->ID );
         }

      }

      property String^ Name 
      {

         // Gets or sets the Name for the curve legend.
         String^ get()
         {
            return name;
         }

         void set( String^ value )
         {
            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, (dynamic_cast<CurveLegendAccessibleObject^>(AccessibilityObject))->ID );
            }
         }

      }

      property bool Selected 
      {

         // Gets or sets the Selected state for the curve legend.
         bool get()
         {
            return selected;
         }

         void set( bool 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, (dynamic_cast<CurveLegendAccessibleObject^>(AccessibilityObject))->ID );
            }
         }

      }

      property System::Drawing::Size Size 
      {

         // Gets the Size for the curve legend.
         System::Drawing::Size get()
         {
            int legendHeight = chart->Font->Height + 4;
            Graphics^ g = chart->CreateGraphics();
            int legendWidth = (int)g->MeasureString( Name, chart->Font ).Width + 4;
            return System::Drawing::Size( legendWidth, legendHeight );
         }

      }

   };


private:

   // class CurveLegend
   CurveLegend^ legend1;
   CurveLegend^ legend2;

public:
   ChartControl()
   {
      
      // The ChartControl draws the chart in the OnPaint .
      SetStyle( ControlStyles::ResizeRedraw, true );
      SetStyle( ControlStyles::DoubleBuffer, true );
      SetStyle( ControlStyles::AllPaintingInWmPaint, true );
      this->BackColor = System::Drawing::Color::White;
      this->Name = "ChartControl";
      this->Click += gcnew System::EventHandler( this, &ChartControl::ChartControl_Click );
      this->QueryAccessibilityHelp += gcnew System::Windows::Forms::QueryAccessibilityHelpEventHandler( this, &ChartControl::ChartControl_QueryAccessibilityHelp );
      
      // The CurveLengend is not Control-based, it just
      // represents the parts of the legend.
      legend1 = gcnew CurveLegend( this,"A" );
      legend1->Location = Point(20,30);
      legend2 = gcnew CurveLegend( this,"B" );
      legend2->Location = Point(20,50);
   }



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

   virtual void OnPaint( PaintEventArgs^ e ) override
   {
      
      // The ChartControl draws the chart in the OnPaint .
      System::Windows::Forms::UserControl::OnPaint( e );
      Rectangle bounds = this->ClientRectangle;
      int border = 5;
      
      // Draws the legends first.
      StringFormat^ format = gcnew StringFormat;
      format->Alignment = StringAlignment::Center;
      format->LineAlignment = StringAlignment::Center;
      if ( legend1 != nullptr )
      {
         if ( legend1->Selected )
         {
            e->Graphics->FillRectangle( gcnew 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 != nullptr )
      {
         if ( legend2->Selected )
         {
            e->Graphics->FillRectangle( gcnew 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 );
      array<Point>^ temp1 = {Point(bounds.Left,bounds.Bottom),Point(bounds.Left + bounds.Width / 3,bounds.Top + bounds.Height / 5),Point(bounds.Right - bounds.Width / 3,(bounds.Top + bounds.Bottom) / 2),Point(bounds.Right,bounds.Top)};
      array<Point>^curve1 = temp1;
      array<Point>^ temp2 = {Point(bounds.Left,bounds.Bottom - bounds.Height / 3),Point(bounds.Left + bounds.Width / 3,bounds.Top + bounds.Height / 5),Point(bounds.Right - bounds.Width / 3,(bounds.Top + bounds.Bottom) / 2),Point(bounds.Right,bounds.Top + bounds.Height / 2)};
      array<Point>^curve2 = temp2;
      
      // 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.
   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
   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;
      }
   }


public:

   property array<CurveLegend^>^ Legends 
   {

      // Gets an array of CurveLengends used in the Chart.
      array<CurveLegend^>^ get()
      {
         array<CurveLegend^>^temp3 = {legend1,legend2};
         return temp3;
      }

   }

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

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


      property System::Windows::Forms::AccessibleRole Role 
      {

         // Gets the role for the Chart. This is used by accessibility programs.
         virtual System::Windows::Forms::AccessibleRole get() override
         {
            return ::AccessibleRole::Chart;
         }

      }

      property AccessibleStates State 
      {

         // Gets the state for the Chart. This is used by accessibility programs.
         virtual AccessibleStates get() override
         {
            return AccessibleStates::ReadOnly;
         }

      }

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


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

         return nullptr;
      }


   internal:

      // 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 )
      {
         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 nullptr;
      }


      // 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.
      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) != (AccessibleSelection)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) != (AccessibleSelection)0 )
            {
               chartControl->Legends[ childID ]->Selected = true;
            }
            
            // AccessibleSelection->AddSelection means that the CurveLegend will be unselected.
            if ( (selection & AccessibleSelection::RemoveSelection) != (AccessibleSelection)0 )
            {
               chartControl->Legends[ childID ]->Selected = false;
            }
         }
      }

   };

   // class ChartControlAccessibleObject
};


// class ChartControl
public ref class Form1: public System::Windows::Forms::Form
{
private:

   // Test out the Chart Control.
   ChartControl^ chart1;

public:
   Form1()
   {
      
      // Create a chart control and add it to the form.
      this->chart1 = gcnew ChartControl;
      this->ClientSize = System::Drawing::Size( 920, 566 );
      this->chart1->Location = System::Drawing::Point( 47, 16 );
      this->chart1->Size = System::Drawing::Size( 600, 400 );
      this->Controls->Add( this->chart1 );
   }

};


// class Form1

[STAThread]
int main()
{
   Application::Run( gcnew Form1 );
}
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

상속 계층 구조

System.Object
   System.MarshalByRefObject
     System.Runtime.InteropServices.StandardOleMarshalObject
      System.Windows.Forms.AccessibleObject
         파생 클래스

스레드로부터의 안전성

이 형식의 모든 public static(Visual Basic의 경우 Shared) 멤버는 스레드로부터 안전합니다. 인터페이스 멤버는 스레드로부터 안전하지 않습니다.

플랫폼

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework에서 모든 플래폼의 모든 버전을 지원하지는 않습니다. 지원되는 버전의 목록은 시스템 요구 사항을 참조하십시오.

버전 정보

.NET Framework

2.0, 1.1, 1.0에서 지원

참고 항목

참조

AccessibleObject 멤버
System.Windows.Forms 네임스페이스