AccessibleObject.Bounds 属性

获取辅助性对象的位置和大小。

**命名空间:**System.Windows.Forms
**程序集:**System.Windows.Forms(在 system.windows.forms.dll 中)

语法

声明
Public Overridable ReadOnly Property Bounds As Rectangle
用法
Dim instance As AccessibleObject
Dim value As Rectangle

value = instance.Bounds
public virtual Rectangle Bounds { get; }
public:
virtual property Rectangle Bounds {
    Rectangle get ();
}
/** @property */
public Rectangle get_Bounds ()
public function get Bounds () : Rectangle

属性值

表示辅助性对象的界限的 Rectangle

异常

异常类型 条件

COMException

无法检索控件的界限。

备注

Bounds 属性按屏幕坐标检索对象边框。如果对象具有非矩形形状,则该属性表示完全包围整个对象区域的最小矩形。因此,对于非矩形对象(例如列表视图项),如果通过调用 HitTest 方法进行测试,对象边框的坐标或许会失败,原因是 HitTest 根据一个个的像素来确定对象的边界。

给继承者的说明 如果此辅助性对象包装了系统控件,默认实现将返回该对象的边框;否则它将返回 Rectangle.Empty。所有可视辅助性对象都必须支持此方法。声音对象不支持此方法。

示例

下面的示例演示了如何创建一个具有辅助功能的图表控件,并使用 AccessibleObjectControl.ControlAccessibleObject 类来公开辅助性信息。该控件绘制两条带有图例的曲线。CreateAccessibilityInstance 方法使用从 ControlAccessibleObject 派生的 ChartControlAccessibleObject 类,为图表控件提供自定义辅助性信息。因为图表图例不是实际的基于 Control 的控件,而是由图表控件绘制的,所以它不提供任何内置的辅助性信息。因此,ChartControlAccessibleObject 类重写 GetChild 方法以返回 CurveLegendAccessibleObject(表示该图例各部分的辅助性信息)。当具有辅助功能的应用程序使用该控件时,该控件能提供必需的辅助性信息。

这段代码摘录演示了如何重写 Bounds 属性。有关完整的代码示例,请参见 AccessibleObject 类概述。

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

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

平台

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 类
AccessibleObject 成员
System.Windows.Forms 命名空间
DefaultAction
Description
Help
KeyboardShortcut
Name
Parent
Role
State
Value