计算多行字符串的文本范围 [英] Calculate text extent of multi-line string

查看:65
本文介绍了计算多行字符串的文本范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我有一个多行字符串需要在具有固定宽度可变高度的矩形区域中绘制.在矩形中绘制字符串时,如果线的长度超过区域的宽度,则超​​出的部分将放入新的线中.

我需要计算文本区域的边界矩形的高度.我该怎么做?

我确实检查了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 the CDC::DrawTextEx() function with the DT_CALCRECT flag set in nFormat and the rect you wish to draw to in lpRect.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆