AccessibleObject.Select(AccessibleSelection) 方法

定義

修改選取或者移動可存取物件的鍵盤焦點。Modifies the selection or moves the keyboard focus of the accessible object.

public:
 virtual void Select(System::Windows::Forms::AccessibleSelection flags);
public virtual void Select (System.Windows.Forms.AccessibleSelection flags);
abstract member Select : System.Windows.Forms.AccessibleSelection -> unit
override this.Select : System.Windows.Forms.AccessibleSelection -> unit
Public Overridable Sub Select (flags As AccessibleSelection)

參數

flags
AccessibleSelection

其中一個 AccessibleSelection 值。One of the AccessibleSelection values.

例外狀況

無法執行選取。The selection cannot be performed.

範例

下列範例示範如何建立可感知存取範圍的圖表控制項,並使用 AccessibleObject 和 @no__t 1 類別來公開可存取的資訊。The following example demonstrates the creation of an accessibility-aware chart control, using the AccessibleObject and Control.ControlAccessibleObject classes to expose accessible information. 控制項繪製兩個曲線和一個圖例。The control plots two curves along with a legend. 衍生自 ControlAccessibleObject 的 @no__t 0 類別,會用於 @no__t 2 方法中,以便為 chart 控制項提供自訂的可存取訊號。The ChartControlAccessibleObject class, which derives from ControlAccessibleObject, is used in the CreateAccessibilityInstance method to provide custom accessible information for the chart control. 因為圖表圖例不是實際的 @no__t 0 型控制項,而是由 chart 控制項繪製,所以沒有任何內建的可存取訊號。Since the chart legend is not an actual Control -based control, but instead is drawn by the chart control, it does not have any built-in accessible information. 因此,@no__t 0 類別會覆寫 GetChild 方法,以傳回代表圖例每個部分之可存取訊號的 CurveLegendAccessibleObjectBecause of this, the ChartControlAccessibleObject class overrides the GetChild method to return the CurveLegendAccessibleObject that represents accessible information for each part of the legend. 當可存取的感知應用程式使用此控制項時,控制項可以提供必要的可存取訊號。When an accessible-aware application uses this control, the control can provide the necessary accessible information.

這段程式碼示範如何覆寫 Select 方法。This code demonstrates shows overriding the Select method. 如需完整的程式碼範例,請參閱 AccessibleObject 類別總覽。See the AccessibleObject class overview for the complete code example.

   // 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 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 Class CurveLegendAccessibleObject
    Inherits AccessibleObject

    Private curveLegend As CurveLegend
    
    Public Sub New(curveLegend As CurveLegend)
        Me.curveLegend = curveLegend
    End Sub
    
    ' 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

備註

應用程式可以使用這個方法來執行複雜的選取作業。Applications can use this method to perform complex selection operations.

以下描述在呼叫 Select 來執行複雜的選取作業時,要指定的 @no__t 0 值。The following describes which AccessibleSelection values to specify when calling Select to perform complex selection operations.

運算Operation 旗標組合Flag Combination
模擬按一下To simulate a click AccessibleSelection.TakeFocus OR AccessibleSelection.TakeSelection注意: 如果從您自己的應用程式中呼叫,則此組合不會選取所需的控制項。AccessibleSelection.TakeFocus OR AccessibleSelection.TakeSelection Note: This combination will not select the desired control if called from within your own application. 不過,如果從外部應用程式呼叫,它會有想要的效果。It will have the desired effect, however, if called from an external application.
若要藉由模擬 CTRL + 按一下來選取目標專案To select a target item by simulating CTRL + click AccessibleSelection.TakeFocus OR AccessibleSelection.AddSelectionAccessibleSelection.TakeFocus OR AccessibleSelection.AddSelection
若要藉由模擬 CTRL + 按一下來取消選取目標專案To cancel selection of a target item by simulating CTRL + click AccessibleSelection.TakeFocus OR AccessibleSelection.RemoveSelectionAccessibleSelection.TakeFocus OR AccessibleSelection.RemoveSelection
模擬 SHIFT + 按一下To simulate SHIFT + click AccessibleSelection.TakeFocus OR AccessibleSelection.ExtendSelectionAccessibleSelection.TakeFocus OR AccessibleSelection.ExtendSelection
若要選取某個範圍的物件,並將焦點放在最後一個物件上To select a range of objects and put focus on the last object 在起始物件上指定 AccessibleSelection.TakeFocus,以設定選取錨點。Specify AccessibleSelection.TakeFocus on the starting object to set the selection anchor. 然後再次呼叫 Select,並在最後一個物件上指定 AccessibleSelection.TakeFocus @ no__t-2 @ no__t-3。Then call Select again and specify AccessibleSelection.TakeFocusORAccessibleSelection.ExtendSelection on the last object.
取消選取所有物件To deselect all objects 在任何物件上指定 AccessibleSelection.TakeSelectionSpecify AccessibleSelection.TakeSelection on any object. 此旗標會取消選取所選的所有物件,但只會選取其中一個。This flag deselects all selected objects except the one just selected. 然後再次呼叫 Select,並在相同的物件上指定 AccessibleSelection.RemoveSelectionThen call Select again and specify AccessibleSelection.RemoveSelection on the same object.

給繼承者的注意事項

所有可選取或接收鍵盤焦點的物件都必須支援這個方法。All objects that can be selected or receive the keyboard focus must support this method.

適用於