DrawText如何使多行文字居中
来源:互联网 发布:人人贷网络平台 编辑:程序博客网 时间:2024/06/05 15:09
(1)DT_WORDBREAK
只能截断单词。例如如果输入一连串英文字符,那么它会当做一个单词来处理,而不会自动换行。而对于中文字符则可以。如果要对所有字符都可以像Edit控件中那样自动换行,那么可以使用DT_WORDBREAK | DT_EDITCONTROL
(2)DT_CALRECT的使用
对于一段text,要计算他的显示大小,那么可以使用DT_CALRECT标志。其中的rect参数属于IN/OUT类型。输出时,左上角坐标不变,右下角坐标改变。函数返回值是文本的高度。当然,它要与不同格式标志一起使用得到的结果是不一样的。例如,DT_CALRECT | DT_SINGLELINE 时,它只扩展传入rect的width,而在多行显示的时候,即DT_WORDBREAK | DT_WORDBREAK | DT_EDITCONTROL,仅仅扩展height,width不变。
DT_CALCRECT Determines the width and height of the rectangle. If there are multiple lines of text, DrawText will use the width of the rectangle pointed to by lpRect and extend the base of the rectangle to bound the last line of text. If there is only one line of text, DrawText will modify the right side of the rectangle so that it bounds the last character in the line. In either case, DrawText returns the height of the formatted text, but does not draw the text.
(3)DT_CENTER 与 DT_VCENTER
DT_VCENTER只对单行文字的竖直居中有用。DT_CENTER 对单行和多行文字都有用,但只能水平居中。
(4)多行文字的竖直居中
思路:根据显示中心,重新计算要求的显示范围
具体方法:
// = 把str内容显示到客户区的中间,但是每行宽度限定为200,让其自动换行
CRect clientRect;
GetClientRect(clientRect); // 获得客户区范围
CRect rect;
rect.left = rect.top = 0;
rect.right = 200;
rect.bottom = clientRect.bottom; // 限定宽度
CString str = "我是来自非洲的姑娘。心中向往神秘的东方,背起行囊寻找梦想,那是龙的故乡
这里的人纯朴善良,淡淡微笑挂脸庞";
CRect temp = rect;
int height = pDC->DrawText(str,temp,DT_CENTER | DT_WORDBREAK | DT_CALCRECT | DT_EDITCONTROL); // 获得文本高度
rect.DeflateRect(0,(rect.Height() - height) / 2); // 改变rect
pDC->DrawText(str,rect, DT_CENTER | DT_EDITCONTROL | DT_WORDBREAK);
闻香止步 收集于:http://blog.pfan.cn/yuqiexing/40715.html
淘宝店 摆件 饰品 *木雕系列*:海南黄花梨、越南黄花梨、草花梨、小叶紫檀、黑檀、绿檀木、黄杨木、桃木发簪 木梳 樟木壁挂 佛珠 车饰 摆件
http://shop36570193.taobao.com
- DrawText如何使多行文字居中
- DrawText如何使多行文字居中
- DrawText如何使多行文字居中
- DrawText如何使多行文字居中
- DrawText多行文本垂直居中
- 如何实现多行文字垂直居中
- 多行文字居中
- 多行文字居中
- Android drawText() 绘制多行文字
- android drawtext 如何使文字居中
- 如何让多行文字与图片垂直居中
- 多行文字垂直居中
- css 多行文字居中
- canvas drawText 如何居中显示。
- lineheight使图片多行文字垂直居中
- 多行文字的垂直水平居中
- 多行文字的垂直居中
- css布局-多行文字垂直居中
- Informix的触发器的使用
- new 和 override比较
- html中的表单元素
- Attribute在.NET编程中的应用(五)
- STL中List,Vector,Map,Set的理解
- DrawText如何使多行文字居中
- Attribute在.NET编程的应用(六)
- Java技巧:向Web站点发送POST请求
- MISRA C指导指南解读系列10(MISRA C规则114-127)
- wxWidgets的使用方法[转载]
- Linux日志文件utmp、wtmp、lastlog、messages
- x-headers
- 29.avi 【实际需求中的用户-角色模型】
- gsoap编译碰到的问题