计算多行字符串的文本范围 [英] Calculate text extent of multi-line string
问题描述
大家好,
我有一个多行字符串需要在具有固定宽度和可变高度的矩形区域中绘制.在矩形中绘制字符串时,如果线的长度超过区域的宽度,则超出的部分将放入新的线中.
我需要计算文本区域的边界矩形的高度.我该怎么做?
我确实检查了CDC的GetTextExtend ...()函数,但它们只允许获取单行字符串的范围.
请在这方面帮助我.
在此先感谢.
Quy
Hi All,
I have a multi-line string need to be drawn in a rectangular area which has fixed-width and variable height. As the string being drawn in the rectangle, if a line''s length exceeds the area''s width, the exceeding part will be put in to a new line.
What I need is to calculate height of boundary rectangle of text area. How can i do it?
I did check GetTextExtend...() functions of CDC, but they allow to get extent of SINGLE line string only.
Please help me in this regard.
Thanks in Advance.
Quy
推荐答案
您可以将CDC::DrawTextEx()
函数与在nFormat
中设置的DT_CALCRECT
标志以及要在lpRect
中绘制的矩形一起使用.
这将扩展矩形的底部以适合您的多行字符串.
看看:
CDC :: DrawTextEx() [ DrawTextEx() [
You can use theCDC::DrawTextEx()
function with theDT_CALCRECT
flag set innFormat
and the rect you wish to draw to inlpRect
.
This will expand the bottom of the rect to fit you multi line string.
Take a look at:
CDC::DrawTextEx()[^]
However IMO the better explination of this function is teh corrasponding win32 function which describes the flags better, found here:
DrawTextEx()[^]
这篇关于计算多行字符串的文本范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!