CGpStringFormat.GetMeasurableCharacterRangeCountmethod
Gets the number of measurable character ranges that are currently set.
Syntax
FUNCTION GetMeasurableCharacterRangeCount () AS INT
Return value
This method returns an integer that indicates the number of character ranges that can be measured by MeasureCharacterRanges.
Description
Gets the number of measurable character ranges that are currently set. The character ranges that are set can be measured in a string by using the MeasureCharacterRanges method.
Example
' ======================================================================================== ' The following example defines three ranges of character positions within a string and sets ' those ranges in a StringFormat object. Next, the StringFormat::GetMeasurableCharacterRangeCount ' method is used to get the number of character ranges that are currently set in the StringFormat ' object. This number is then used to allocate a buffer large enough to store the regions ' that correspond with the ranges. Then, the MeasureCharacterRanges method is used to get ' the three regions of the display that are occupied by the characters that are specified ' by the ranges. ' Remarks: It doesn't work with the 64-bit headers because they lack a declare for the ' GdipMeasureCharacterRanges function. ' ======================================================================================== SUB Example_GetMeasurableCharacterRangesCount (BYVAL hdc AS HDC)
' // Create a graphics object from the window device context DIM graphics AS CGpGraphics = hdc ' // Set the scale transform graphics.ScaleTransformForDpi
' // Brushes and pens used for drawing and painting DIM blueBrush AS CGpSolidBrush = ARGB_BLUE DIM redBrush AS CGpSolidBrush = GDIP_ARGB(100, 255, 0, 0) ' partially transparent DIM blackPen AS CGpPen = ARGB_RED
' // Layout rectangles used for drawing strings DIM layoutRect AS GpRectF = (20.0, 20.0, 130.0, 130.0)
' // Three ranges of character positions within the string DIM charRanges(2) AS GpCharacterRange charRanges(0).First = 3 : charRanges(0).Length = 5 charRanges(1).First = 15 : charRanges(1).Length = 2 charRanges(2).First = 30 : charRanges(2).Length = 15
' // Font and string format used to apply to string when drawing DIM myFont AS CGpFont = CGpFont("Times New Roman", AfxGdipPointsToPixels(16, TRUE), FontStyleRegular, UnitPixel) DIM strFormat AS CGpStringFormat
DIM wszText AS WSTRING * 260 wszText = "The quick, brown fox easily jumps over the lazy dog."
' // Set three ranges of character positions. strFormat.SetMeasurableCharacterRanges(3, @charRanges(0))
' // Get the number of ranges that have been set, and allocate memory to ' // store the regions that correspond to the ranges. DIM nCount AS LONG = strFormat.GetMeasurableCharacterRangeCount DIM rgCharRangeRegions(nCount - 1) AS CGpRegion
' // Get the regions that correspond to the ranges within the string graphics.MeasureCharacterRanges(@wszText, -1, @myFont, @layoutRect, @strFormat, nCount, @rgCharRangeRegions(0)) graphics.DrawString(@wszText, -1, @myFont, @layoutRect, @strFormat, @blueBrush) graphics.DrawRectangle(@blackPen, @layoutRect) FOR i AS LONG = 0 TO nCount - 1
graphics.FillRegion(@redBrush, @rgCharRangeRegions(i))
NEXT
END SUB ' ========================================================================================
Reference
- Include file
CGpStringFormat.inc - Defined in AfxNova/CGpStringFormat.inc:244
- Documented in Graphics/GdiPlus Classes/CGpStringFormat Class.md
- Topic: CGpStringFormat Class