Help Center

GdiPlusStringFormatoperator

GpStringFormat

Graphicsoperatordocumented

Syntax

PRIVATE OPERATOR GdiPlusStringFormat.@ () AS GpStringFormat PTR PTR

Description

The StringFormat functions allow to set and get text layout information (such as alignment, orientation, tab stops, and clipping) and display manipulations (such as trimming, font substitution for characters that are not supported by the requested font, and digit substitution for languages that do not use Western European digits). A StringFormat object can be passed to the GdipDrawString function to format a string.

Examples

' ======================================================================================== TYPE GdiPlusStringFormat Public: m_StringFormat AS GpStringFormat PTR DECLARE CONSTRUCTOR (BYVAL stringFormat AS GpStringFormat PTR = NULL) DECLARE CONSTRUCTOR (BYVAL formatAttributes AS INT_, BYVAL language AS LANGID) DECLARE DESTRUCTOR DECLARE OPERATOR @ () AS GpStringFormat PTR PTR DECLARE OPERATOR CAST () AS GpStringFormat PTR END TYPE ' ========================================================================================

' ===================================================================================== ' Creates and initializes a default StringFormat object or clones it from another StringFormat object. ' ===================================================================================== PRIVATE CONSTRUCTOR GdiPlusStringFormat (BYVAL stringFormat AS GpStringFormat PTR = NULL) IF stringFormat THEN

SetLastError(GdipCloneStringFormat(stringFormat, @m_StringFormat))

ELSE

SetLastError(GdipCreateStringFormat(0, LANG_NEUTRAL, @m_StringFormat))

END IF END CONSTRUCTOR ' ===================================================================================== ' ===================================================================================== ' Creates a StringFormat object based on string format flags and a language. ' ===================================================================================== PRIVATE CONSTRUCTOR GdiPlusStringFormat (BYVAL formatFlags AS INT_ = 0, BYVAL language AS LANGID = LANG_NEUTRAL) SetLastError(GdipCreateStringFormat(formatFlags, language, @m_StringFormat)) END CONSTRUCTOR ' ======================================================================================== ' ======================================================================================== ' Cleanup ' ======================================================================================== PRIVATE DESTRUCTOR GdiPlusStringFormat IF m_StringFormat THEN SetLastError(GdipDeleteStringFormat(m_StringFormat)) END DESTRUCTOR ' ======================================================================================== ' ======================================================================================== ' Returns a pointer to the GpStringFormat object ' ======================================================================================== PRIVATE OPERATOR * (BYREF fmt AS GdiPlusStringFormat) AS GpStringFormat PTR RETURN fmt.m_StringFormat END OPERATOR ' ======================================================================================== ' ======================================================================================== ' Returns the address of a pointer to the GpStringFormat object ' ======================================================================================== PRIVATE OPERATOR GdiPlusStringFormat.@ () AS GpStringFormat PTR PTR RETURN @m_StringFormat END OPERATOR ' ======================================================================================== ' ======================================================================================== PRIVATE OPERATOR GdiPlusStringFormat.CAST () AS GpStringFormat PTR RETURN m_StringFormat END OPERATOR ' ========================================================================================

' ======================================================================================== ' The following example uses the specified formatting to draw a string in a layout rectangle. ' ======================================================================================== SUB Example_CreateStringFormat (BYVAL hdc AS HDC)

' // Create a graphics object from the device context DIM graphics AS GdiPlusGraphics = hdc ' // Set the scale transform graphics.ScaleTransform

' // Create the font DIM fontFamily AS GdiPlusFontFamily ="Times New Roman" DIM font AS GdiPlusFont = GdiPlusFont(*fontFamily, AfxGdipPointsToPixels(16, TRUE), FontStyleRegular, UnitPixel)

' // Create a StringFormat object DIM format AS GdiPlusStringFormat = GdiPlusStringFormat(0, LANG_NEUTRAL) GdipSetStringFormatAlign(format, StringAlignmentCenter)

' // Create a solid brush DIM solidBrush AS GdiPlusSolidBrush = ARGB_BLACK

' // Draw the string DIM wszText AS WSTRING * 64 = "Sample text" DIM rcf AS GpRectF = (30, 30, 200, 25) GdipDrawString(graphics, wszText, LEN(wszText), font, @rcf, format, solidBrush)

' // Create a Pen DIM pen AS GdiPlusPen = GdiPlusPen(ARGB_BLACK, 3, UnitPixel) GdipScalePenTransform(pen, graphics.dpiRatioX, graphics.dpiRatioY, MatrixOrderPrepend)

' // Draw a rectangle GdipDrawRectangle(graphics, *pen, rcf.x, rcf.y, rcf.Width, rcf.Height)

END SUB ' ========================================================================================

Reference

  • Defined in AfxNova/AfxGdipObjects.inc:1938
  • Documented in Graphics/GdiPlus Flat Api/GdiPlus Objects.md
  • Topic: GdiPlus Objects