描述
在指定的Graphics对象的当前单位这个字体的行距.行间距是连续两行文本的基线之间的垂直距离.因此,行间距包括行之间的空白以及字符本身的高度.
C++ Syntax
REAL GetHeight( [in] const Graphics* graphics ) const; |
FreeBASIC 语法
FUNCTION GetHeight ( _ BYVAL pGraphics AS CGpGraphics PTR _ ) AS SINGLE |
参数
pGraphics
[in]指向Graphics对象的单元和垂直分辨率是用于高度计算.
返回值
此方法返回此字体的行间距.
备注
如果字体单位设置为比其他任何UnitPixel,高度,以像素为单位,使用指定的Graphics对象的垂直分辨率计算.例如,假定字体单位为英寸,字体的大小0.3.也假设相应的字体,EM高度2048和线间距的2355.如果Graphics对象单位的Graphics对象UnitPixel和垂直分辨率为96点每英寸的高度计算如下:
2355*(0.3/2048)*96 = 33.1171875
继续同样的例子,假设的Graphics对象单位以外的其他UnitPixel,说UnitMillimeter.然后(使用1英寸= 25.4毫米)毫米的高度,计算如下:
2355*(0.3/2048)25.4 = 8.762256
引用文件
CGpFont.inc (include CGdiPlus.inc)
示例
' ========================================================================================
' The following example creates a Font object, retrieves the height of the Font object, and
' uses the height to position two lines of text, with the second line directly below the first.
' ========================================================================================
SUB Example_GetHeight (BYVAL hdc AS HDC)
' // Create a graphics object from the window device context
DIM graphics AS CGpGraphics = hdc
' // Get the DPI scaling ratio
DIM rxRatio AS SINGLE = graphics.GetDpiX / 96
DIM ryRatio AS SINGLE = graphics.GetDpiY / 96
' // Set the scale transform
graphics.ScaleTransform(rxRatio, ryRatio)
' // Create a Font object.
DIM font AS CGpFont = CGpFont("Arial", AfxPointsToPixelsX(16) / rxRatio)
' // Draw text with myFont.
DIM solidbrush_1 AS CGpSolidBrush = GDIP_ARGB(255, 0, 0, 0)
DIM wszText AS WSTRING * 260 = "The first line of text"
graphics.DrawString(@wszText, -1, @font, 0, 0, @solidbrush_1)
' // Get the height of myFont.
DIM height AS SINGLE = font.GetHeight(@graphics)
' // Draw text immediately below the first line of text
DIM solidbrush_2 AS CGpSolidBrush = GDIP_ARGB(255, 255, 0, 0)
DIM wszText2 AS WSTRING * 260 = "The second line of text"
graphics.DrawString(@wszText2, -1, @font, 0, height, @solidbrush_2)
END SUB
' ========================================================================================