Help Center

CGpStringFormat.SetTrimmingmethod

Sets the trimming style for this **StringFormat** object.

GraphicsmethodCGpStringFormat.incdocumented

Syntax

FUNCTION SetTrimming (BYVAL trimming AS StringTrimming) AS GpStatus

Parameters

NameDescription
trimmingElement of the StringTrimming enumeration that specifies the style of trimming to be performed on the string.

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 trimming style for this StringFormat object. The trimming style determines how to trim a string so that it fits into the layout rectangle.

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_SetTrimming (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(18, TRUE), FontStyleRegular, UnitPixel)

' // Create a string format object and set its trimming style DIM stringFormat AS CGpStringFormat stringFormat.SetFormatFlags(StringFormatFlagsLineLimit) stringFormat.SetTrimming(StringTrimmingEllipsisWord)

' // Use the StringFormat object in a call to DrawString DIM wszText AS WSTRING * 260 = "One two three four five six seven eight nine ten" graphics.DrawString(@wszText, LEN(wszText), @pFont, 30, 30, 160, 60, @stringFormat, @solidBrush)

' // Draw the rectangle that encloses the text DIM pen AS CGpPen = ARGB_RED graphics.DrawRectangle(@pen, 30, 30, 160, 60)

END SUB

Reference

  • Include file CGpStringFormat.inc
  • Defined in AfxNova/CGpStringFormat.inc:215
  • Documented in Graphics/GdiPlus Classes/CGpStringFormat Class.md
  • Topic: CGpStringFormat Class