CGpGraphics.MeasureStringmethod
Measures the extent of the string in the specified font, format, and layout rectangle.
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
| Name | Description | |
|---|---|---|
pwszString | Pointer to a wide-character string to be measured. Important: For bidirectional languages, such as Arabic, the string length must not exceed 2046 characters. | |
pFont | Pointer to a Font object that specifies the family name, size, and style of the font to be applied to the string. | |
origin | Reference to the point at which the string starts. | |
layoutRect | Reference to the rectangle that bounds the string. | |
stringFormat | Pointer to a StringFormat object that specifies the layout information, such as alignment, trimming, tab stops, and so forth. | |
boundingBox | Pointer to a GpRectF object that receives the rectangle that bounds the string. | |
size | Pointer to a GpSizeF object that receives the width and height of the rectangle that bounds the string. | |
codepointsFitted | Pointer to an INT_ that receives the number of characters that actually fit into the layout rectangle. The default value is a NULL pointer. | |
linesFilled | Pointer 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