CGpStringFormat.SetLineAlignmentmethod
Sets the line alignment of this **StringFormat** object in relation to the origin of the layout rectangle.
Syntax
FUNCTION SetLineAlignment (BYVAL nAlign AS StringAlignment) AS GpStatus
Parameters
| Name | Description | |
|---|---|---|
nAlign | Element of the StringAlignment enumeration that specifies how to align a string in reference to the layout rectangle. |
Return value
If the function succeeds, it returns Ok, which is an element of the GpStatus enumeration.
If the function fails, it returns one of the other elements of the GpStatus enumeration.
Description
Sets the line alignment of this StringFormat object in relation to the origin of the layout rectangle. The line alignment setting specifies how to align the string vertically in the layout rectangle. The layout rectangle is used to position the displayed string.
Example
' ======================================================================================== ' The following example creates a StringFormat object, sets the trimming style, and uses ' the StringFormat object to draw a string. The code also draws the string's layout rectangle. ' ======================================================================================== SUB Example_SetLineAlignment (BYVAL hdc AS HDC)
' // Create a graphics object from the window device context DIM graphics AS CGpGraphics = hdc ' // Set the scale transform graphics.ScaleTransformForDpi
' // Create a red solid brush DIM solidBrush AS CGpSolidBrush = ARGB_RED ' // Create a font family from name DIM fontFamily AS CGpFontFamily = "Times New Roman" ' // Create a font from the font family DIM pFont AS CGpFont = CGpFont(@fontFamily, AfxGdipPointsToPixels(16, TRUE), FontStyleRegular, UnitPixel)
' // Create a string format object and set the alignment DIM stringFormat AS CGpStringFormat stringFormat.SetLineAlignment(StringAlignmentCenter)
' // Use the StringFormat object in a call to DrawString DIM wszText AS WSTRING * 260 = "This text was formatted by a StringFormat object." graphics.DrawString(@wszText, LEN(wszText), @pFont, 30, 30, 150, 200, @stringFormat, @solidBrush)
' // Draw the rectangle that encloses the text DIM pen AS CGpPen = ARGB_RED graphics.DrawRectangle(@pen, 30, 30, 150, 200)
END SUB ' ========================================================================================
Reference
- Include file
CGpStringFormat.inc - Defined in AfxNova/CGpStringFormat.inc:117
- Documented in Graphics/GdiPlus Classes/CGpStringFormat Class.md
- Topic: CGpStringFormat Class