IDWriteTextFormat::SetTextAlignment method (dwrite.h)

Sets the alignment of text in a paragraph, relative to the leading and trailing edge of a layout box for a IDWriteTextFormat interface.

Syntax

HRESULT SetTextAlignment(
  DWRITE_TEXT_ALIGNMENT textAlignment
);

Parameters

textAlignment

Type: DWRITE_TEXT_ALIGNMENT

The text alignment option being set for the paragraph of type DWRITE_TEXT_ALIGNMENT. For more information, see Remarks.

Return value

Type: HRESULT

This method can return one of these values.

Return code Description
S_OK
The method succeeded.
E_INVALIDARG
The textAlignment argument is invalid.

Remarks

The text can be aligned to the leading or trailing edge of the layout box, or it can be centered. The following illustration shows text with the alignment set to DWRITE_TEXT_ALIGNMENT_LEADING, DWRITE_TEXT_ALIGNMENT_CENTER, and DWRITE_TEXT_ALIGNMENT_TRAILING, respectively.

Illustration of text paragraphs with leading, centered, and trailing alignment
Note  The alignment is dependent on reading direction, the above is for left-to-right reading direction. For right-to-left reading direction it would be the opposite.
 
See DWRITE_TEXT_ALIGNMENT for more information.

Examples

if (SUCCEEDED(hr))
{
    hr = pTextFormat_->SetTextAlignment(DWRITE_TEXT_ALIGNMENT_CENTER);
}

Requirements

Requirement Value
Minimum supported client Windows 7, Windows Vista with SP2 and Platform Update for Windows Vista [desktop apps | UWP apps]
Minimum supported server Windows Server 2008 R2, Windows Server 2008 with SP2 and Platform Update for Windows Server 2008 [desktop apps | UWP apps]
Target Platform Windows
Header dwrite.h
Library Dwrite.lib
DLL Dwrite.dll

See also

IDWriteTextFormat