Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

TextPattern.HorizontalTextAlignmentAttribute Field

Identifies the HorizontalTextAlignment attribute of a text range.

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

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

This attribute represents the horizontal text alignment applied to the paragraph(s) associated with the calling text range.

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

HorizontalTextAlignment. The default value is Left

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

NoteNote:

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

private void GetHorizontalTextAlignmentAttribute()
{
    // Start application.
    Process p = Process.Start("Notepad.exe", "text.txt");

    // target --> The root AutomationElement.
    AutomationElement target = AutomationElement.FromHandle(p.MainWindowHandle);

    // Specify the control type we're looking for, in this case 'Document'
    PropertyCondition cond = new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Document);

    AutomationElement textProvider = target.FindFirst(TreeScope.Descendants, cond);

    TextPattern textpatternPattern = textProvider.GetCurrentPattern(TextPattern.Pattern) as TextPattern;

    if (textpatternPattern == null)
    {
        Console.WriteLine("Root element does not contain a descendant that supports TextPattern.");
        return;
    }

    Object oAttribute = textpatternPattern.DocumentRange.GetAttributeValue(TextPattern.HorizontalTextAlignmentAttribute);
    if (oAttribute == TextPattern.MixedAttributeValue)
    {
        Console.WriteLine("Mixed horizontal alignments.");
    }
    else
    {
        Console.WriteLine(oAttribute.ToString());
    }
}

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
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

Show:
© 2014 Microsoft