TextPattern.FontNameAttribute Campo

Definição

Identifica o atributo FontName de um intervalo de texto.

public: static initonly System::Windows::Automation::AutomationTextAttribute ^ FontNameAttribute;
public static readonly System.Windows.Automation.AutomationTextAttribute FontNameAttribute;
 staticval mutable FontNameAttribute : System.Windows.Automation.AutomationTextAttribute
Public Shared ReadOnly FontNameAttribute As AutomationTextAttribute 

Valor do campo

AutomationTextAttribute

Exemplos

O exemplo a seguir mostra como obter um valor de atributo para um intervalo de texto no Microsoft Bloco de notas.

Observação

O Microsoft Bloco de notas é usado como o provedor de texto somente para fins de exemplo. O Microsoft Bloco de notas não tem a garantia de dar suporte ao valor do atributo que está sendo solicitado.

/// -------------------------------------------------------------------
/// <summary>
/// Outputs the FontNameAttribute value for a range of text.
/// </summary>
/// <param name="targetTextElement">
/// The AutomationElment that represents a text control.
/// </param>
/// -------------------------------------------------------------------
private void GetFontNameAttribute(AutomationElement targetTextElement)
{
    TextPattern textPattern = 
        targetTextElement.GetCurrentPattern(TextPattern.Pattern) as TextPattern;

    if (textPattern == null)
    {
        // Target control doesn't support TextPattern.
        return;
    }

    // If the target control doesn't support selection then return.
    // Otherwise, get the text attribute for the selected text.
    // If there are currently no selections then the text attribute 
    // will be obtained from the insertion point.
    TextPatternRange[] textRanges;
    if (textPattern.SupportedTextSelection == SupportedTextSelection.None)
    {
        return;
    }
    else
    {
        textRanges = textPattern.GetSelection();
    }

    foreach (TextPatternRange textRange in textRanges)
    {
        Object textAttribute =
            textRange.GetAttributeValue(
            TextPattern.FontNameAttribute);

        if (textAttribute == TextPattern.MixedAttributeValue)
        {
            // Returns MixedAttributeValue if the value of the 
            // specified attribute varies over the text range. 
            Console.WriteLine("Mixed fonts.");
        }
        else if (textAttribute == AutomationElement.NotSupported)
        {
            // Returns NotSupported if the specified attribute is 
            // not supported by the provider or the control. 
            Console.WriteLine(
                "FontNameAttribute not supported by provider.");
        }
        else
        {
            Console.WriteLine(textAttribute.ToString());
        }
    }
}
''' -------------------------------------------------------------------
''' <summary>
''' Outputs the FontNameAttribute value for a range of text.
''' </summary>
''' <param name="targetTextElement">
''' The AutomationElement. that represents the text provider.
''' </param>
''' -------------------------------------------------------------------
Private Sub GetFontNameAttribute( _
ByVal targetTextElement As AutomationElement)
    Dim targetTextPattern As TextPattern = _
        DirectCast(targetTextElement.GetCurrentPattern( _
        TextPattern.Pattern), TextPattern)

    If (targetTextPattern Is Nothing) Then
        ' Target control doesn't support TextPattern.
        Return
    End If

    ' If the target control doesn't support selection then return.
    ' Otherwise, get the text attribute for the selected text.
    ' If there are currently no selections then the text attribute 
    ' will be obtained from the insertion point.
    Dim textRanges() As TextPatternRange
    If (targetTextPattern.SupportedTextSelection = SupportedTextSelection.None) Then
        Return
    Else
        textRanges = targetTextPattern.GetSelection()
    End If

    Dim textRange As TextPatternRange
    For Each textRange In textRanges
        Dim textAttribute As Object = _
            textRange.GetAttributeValue( _
            TextPattern.FontNameAttribute)

        If (textAttribute = TextPattern.MixedAttributeValue) Then
            ' Returns MixedAttributeValue if the value of the 
            ' specified attribute varies over the text range. 
            Console.WriteLine("Mixed fonts.")
        ElseIf (textAttribute = AutomationElement.NotSupported) Then
            ' Returns NotSupported if the specified attribute is 
            ' not supported by the provider or the control. 
            Console.WriteLine( _
            "FontNameAttribute not supported by provider.")
        Else
            Console.WriteLine(textAttribute.ToString())
        End If
    Next
End Sub

Comentários

Os valores de exemplo para esse atributo incluem "Arial Black" e "Arial Narrow".

Os valores desse atributo não são localizados.

Esse identificador é usado por aplicativos cliente Automação da Interface do Usuário. Automação da Interface do Usuário provedores devem usar o campo equivalente em TextPatternIdentifiers.

Automação da Interface do Usuário clientes obtêm o valor do atributo chamando GetAttributeValue.

Os valores para esse atributo são do tipo String. O valor padrão é um empty string.

Aplica-se a

Confira também