共用方式為


IRawElementProviderFragmentRoot.GetFocus 方法

定義

擷取這個片段中具有輸入焦點的項目。

public:
 System::Windows::Automation::Provider::IRawElementProviderFragment ^ GetFocus();
public System.Windows.Automation.Provider.IRawElementProviderFragment GetFocus ();
abstract member GetFocus : unit -> System.Windows.Automation.Provider.IRawElementProviderFragment
Public Function GetFocus () As IRawElementProviderFragment

傳回

IRawElementProviderFragment

這個片段中具有輸入焦點之項目的提供者 (如果有);否則為 Null 參考 (在 Visual Basic 中為 Nothing)。

範例

下列程式碼範例顯示清單方塊這個方法的一個可能實作。 它會傳回清單中目前選取的專案。

/// <summary>
/// Returns the child element that is selected when the list gets focus.
/// </summary>
/// <returns>The selected item.</returns>
/// <remarks>
/// SelectedIndex is a class property that maintains the index of the currently
/// selected item in the myItems collection.</remarks>
IRawElementProviderFragment IRawElementProviderFragmentRoot.GetFocus()
{
    if (SelectedIndex >= 0)
    {
        return (IRawElementProviderFragment)myItems[SelectedIndex];
    }
    else
    {
        return null;
    }
}
''' <summary>
''' Returns the child element that is selected when the list gets focus.
''' </summary>
''' <returns>The selected item.</returns>
''' <remarks>
''' SelectedIndex is a class property that maintains the index of the currently
''' selected item in the myItems collection.</remarks>
Function GetFocus() As IRawElementProviderFragment _
    Implements IRawElementProviderFragmentRoot.GetFocus

    If SelectedIndex >= 0 Then
        Return DirectCast(myItems(SelectedIndex), IRawElementProviderFragment)
    Else
        Return Nothing
    End If
End Function 'IRawElementProviderFragmentRoot.GetFocus

備註

如果焦點位於此片段所裝載之另一個架構中的專案上,此方法會傳回裝載該片段的專案。

適用於

另請參閱