This method uses GDI+ functionality to retrieve the height and width of text from text information. This method is recommended when using scripting or other languages that require variant types.
* ImageKit9ALib refers to the ANSI version, ImageKit9Lib refers to the Unicode version, (x86) refers to the 32 bit version, and (x64) refers to the 64 bit version.
Parameters
Name | Explanation |
---|---|
hDC | The device context |
AreaWidth | The maximum width (from 0) |
AreaHeight | The maximum height (from 0) |
Width | Retrieves the width of the text |
Height | Retrieves the height of the text |
charactersFitted | The number of characters in the retrieved text |
linesFilled | The number of lines in the retrieved text |
FormatFlags | The string format information (default is 0) |
UnitMode | Units of measurement (0: pixels, 1: 0.1mm) |
The following constants can be used: (ikPrinterPixel = 0, ikPrinterMM = 1).
Return Value
Returns True (nonzero) if successful. Returns False (0) if unsuccessful.
Explanation
The MeasureStringVariant method uses GDI+ functionality to retrieve the height and width of text from text information.
This method is recommended when using scripting or other languages that require variant types or when using 64 bit builds in VB.NET or C#.
To retrieve the height and width of the text set in the Text property, the following properties should be set: FontName, FontSize, HCentering, VCentering, HotkeyPrefix, Text. If 0 is set in either the AreaWidth or AreaHeight parameters, the height and width of the whole text will be retrieved. However if the AreaWidth and AreaHeight parameters contain values other than 0, then only the height and width of the text contained within that area will be retrieved. The charactersFitted and linesFilled work in the same way. If 0 is set in either the AreaWidth or AreaHeight parameters, then the number of characters or the number of lines in the whole text will be retrieved and returned in the charactersFitted and linesFilled parameters. However if the AreaWidth and AreaHeight parameters contain values other than 0, then the values in the charactersFitted and linesFilled parameters will relate only to the text contained within the area defined by the AreaWidth and AreaHeight parameters.
Also see the MeasureStringVariant method.
If the UnitMode parameter is 0 then the AreaWidth, AreaHeight, Width, Height parameters are in pixel units.
If the UnitMode parameter is 1 then AreaWidth, AreaHeight, Width, Height parameters are in 0.1mm units.
String Format info
Value | Explanation |
---|---|
0x00000001 | Text is displayed from right to left |
0x00000002 | Text is vertically aligned. |
0x00000004 | Parts of characters are allowed to overhang the string's layout rectangle. By default, characters are repositioned to avoid any overhang. |
0x00000020 | Control characters such as the left-to-right mark are shown in the output with a representative glyph. |
0x00000400 | Fallback to alternate fonts for characters not supported in the requested font is disabled. Any missing characters are displayed with the fonts missing glyph, usually an open square. |
0x00000800 | Includes the trailing space at the end of each line. Set this flag to include that space in measurement. |
0x00001000 | Text wrapping between lines when formatting within a rectangle is disabled. This flag is implied when a point is passed instead of a rectangle, or when the specified rectangle has a zero line length. |
0x00002000 | Only entire lines are laid out in the formatting rectangle. By default layout continues until the end of the text, or until no more lines are visible as a result of clipping, whichever comes first. Note that the default settings allow the last line to be partially obscured by a formatting rectangle that is not a whole multiple of the line height. To ensure that only whole lines are seen, specify this value and be careful to provide a formatting rectangle at least as tall as the height of one line. |
0x00004000 | Overhanging parts of glyphs, and unwrapped text reaching outside the formatting rectangle are allowed to show. By default all text and glyph parts reaching outside the formatting rectangle are clipped. |
The values of the MeasureStringVisual method in Visual Basic and .NET should start with &H instead of 0x.
The following constants can be used: (ikDirectionRightToLeft = 0x00000001, ikDirectionVertical = 0x00000002, ikNoFitBlackBox = 0x00000004, ikDisplayFormatControl = 0x00000020, ikNoFontFallback = 0x00000400, ikMeasureTrailingSpaces = 0x00000800, ikNoWrap = 0x00001000, ikLineLimit = 0x00002000, ikNoClip = 0x00004000).
Differences between the ImageKit7/8
The hDC argument's type has changed.