Help Center

CGpGraphics.MeasureStringmethod

Measures the extent of the string in the specified font, format, and layout rectangle.

GraphicsmethodCGpGraphics.incdocumented

Syntax

FUNCTION MeasureString (BYVAL pwszString AS WSTRING PTR, BYVAL length AS INT_, BYVAL pFont AS CGpFont PTR, BYVAL layoutRect AS GpRectF PTR, BYVAL boundingBox AS GpRectF PTR) AS GpStatus
FUNCTION MeasureString (BYVAL pwszString AS WSTRING PTR, BYVAL length AS INT_, BYVAL pFont AS CGpFont PTR, BYVAL layoutRect AS GpPointF PTR, BYVAL boundingBox AS GpRectF PTR) AS GpStatus
FUNCTION MeasureString (BYVAL pwszString AS WSTRING PTR, BYVAL length AS INT_, BYVAL pFont AS CGpFont PTR, BYVAL layoutRect AS GpRectF PTR, BYVAL pStringFormat AS CGpStringFormat PTR, BYVAL boundingBox AS GpRectF PTR) AS GpStatus
FUNCTION MeasureString (BYVAL pwszString AS WSTRING PTR, BYVAL length AS INT_, BYVAL pFont AS CGpFont PTR, BYVAL layoutRect AS GpRectF PTR, BYVAL pStringFormat AS CGpStringFormat PTR, BYVAL boundingBox AS GpPointF PTR) AS GpStatus
FUNCTION MeasureString (BYVAL pwszString AS WSTRING PTR, BYVAL length AS INT_, BYVAL pFont AS CGpFont PTR, BYVAL layoutRect AS GpRectF PTR, BYVAL pStringFormat AS CGpStringFormat PTR, BYVAL boundingBox AS GpRectF PTR, BYREF codepointsFitted AS INT_, BYREF linesFilled AS INT_) AS GpStatus
FUNCTION MeasureString (BYVAL pwszString AS WSTRING PTR, BYVAL length AS INT_, BYVAL pFont AS CGpFont PTR, BYVAL layoutRect AS GpSizeF PTR, BYVAL pStringFormat AS CGpStringFormat PTR, BYVAL boundingBox AS GpSizeF PTR, BYREF codepointsFitted AS INT_, BYREF linesFilled AS INT_) AS GpStatus

Parameters

NameDescription
pwszStringPointer to a wide-character string to be measured. Important: For bidirectional languages, such as Arabic, the string length must not exceed 2046 characters.
pFontPointer to a Font object that specifies the family name, size, and style of the font to be applied to the string.
originReference to the point at which the string starts.
layoutRectReference to the rectangle that bounds the string.
stringFormatPointer to a StringFormat object that specifies the layout information, such as alignment, trimming, tab stops, and so forth.
boundingBoxPointer to a GpRectF object that receives the rectangle that bounds the string.
sizePointer to a GpSizeF object that receives the width and height of the rectangle that bounds the string.
codepointsFittedPointer to an INT_ that receives the number of characters that actually fit into the layout rectangle. The default value is a NULL pointer.
linesFilledPointer to aa INT_ that receives the number of lines that fit into the layout rectangle. The default value is a NULL pointer.

Return value

If the function succeeds, it returns StatusOk, which is an element of the GpStatus enumeration.

If the function fails, it returns one of the other elements of the GpStatus enumeration.

Description

Measures the extent of the string in the specified font, format, and layout rectangle.

Example

' ======================================================================================== ' The following example measures the extent of the string in the specified font, format, ' and layout rectangle. ' ======================================================================================== SUB Example_MeasureString (BYVAL hdc AS HDC)

' // Create a graphics object from the window device context DIM graphics AS CGpGraphics = hdc ' // Set the scale transform DIM rxRatio AS SINGLE = graphics.GetDpiX / 96 DIM ryRatio AS SINGLE = graphics.GetDpiY / 96 graphics.ScaleTransform(rxRatio, ryRatio)

' // Create font (Arial, 16pt) DIM font AS CGpFont = CGpFont("Arial", AfxGdipPointsToPixels(16, TRUE), FontStyleRegular)

' // Create default string format DIM stringFormat AS CGpStringFormat

' // Define layout rectangle and text DIM layoutRect AS GpRectF = (0.0, 0.0, 100.0, 50.0) DIM text AS WSTRING * 64 = "Measure Text"

' // Measure string bounds DIM boundRect AS GpRectF graphics.MeasureString(text, -1, @font, @layoutRect, @stringFormat, @boundRect)

' Draw bounding rectangle for visualization DIM pen AS CGpPen = CGpPen(ARGB_BLACK, 1.0) pen.ScaleTransform(rxRatio, ryRatio) graphics.DrawRectangle(@pen, boundRect.X, boundRect.Y, boundRect.Width, boundRect.Height)

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

Reference

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