TextPattern.FontNameAttribute Field

Identifies the FontName attribute of a text range.

Namespace: System.Windows.Automation
Assembly: UIAutomationClient (in uiautomationclient.dll)

public static readonly AutomationTextAttribute FontNameAttribute
public static final AutomationTextAttribute FontNameAttribute
public static final var FontNameAttribute : AutomationTextAttribute
Not applicable.

Example values for this attribute include "Arial Black" and "Arial Narrow".

The values for this attribute are non-localized.

This identifier is used by UI Automation client applications. UI Automation providers should use the equivalent field in TextPatternIdentifiers.

UI Automation clients get the value of the attribute by calling GetAttributeValue.

Values for this attribute are of type String. The default value is an empty string.

The following example shows how to obtain an attribute value for a range of text in Microsoft Notepad.


Microsoft Notepad is used as the text provider for example purposes only. Microsoft Notepad is not guaranteed to support the attribute value being requested.

/// -------------------------------------------------------------------
/// <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.

    // 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)
        textRanges = textPattern.GetSelection();

    foreach (TextPatternRange textRange in textRanges)
        Object textAttribute =

        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. 
                "FontNameAttribute not supported by provider.");

Windows 98, Windows Server 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

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0

Community Additions