一、 说明
API 函数DrawText可以在规定设备场景的矩形区域内上描绘字体,这为我们制作绘图程序、打印程序提供了方便。函数圆形:
int DrawText(
HDC hDC, //设备场景
LPCTSTR lpString, // 要绘制的字符串
int nCount, // 要绘制的字符串长度
LPRECT lpRect, // 矩形区域
UINT uFormat // 绘制格式
);
DT_TOP = 0; //顶对齐
DT_LEFT = 0; //左对齐
DT_CENTER = 1; //居中
DT_RIGHT = 2; //右对齐
DT_VCENTER = 4; //垂直居中
DT_BOTTOM = 8; //底对齐
DT_WORDBREAK = $10; //允许换行
DT_SINGLELINE = $20; //单行显示
DT_EXPANDTABS = $40;
DT_TABSTOP = $80;
DT_NOCLIP = $100;
DT_EXTERNALLEADING = $200;
DT_CALCRECT = $400;
DT_NOPREFIX = $800;
DT_INTERNAL = $1000;
DT_HIDEPREFIX = $00100000;
DT_PREFIXONLY = $00200000;
DT_EDITCONTROL = $2000;
DT_PATH_ELLIPSIS = $4000;
DT_END_ELLIPSIS = $8000; //结尾显示...
DT_MODIFYSTRING = $10000;
DT_RTLREADING = $20000;
DT_WORD_ELLIPSIS = $40000;
VB程序示例
Private Declare Function DrawText& Lib "user32" Alias "DrawTextA" (ByVal hDC As Long, ByVal lpStr As String, ByVal nCount As Long, lpRect As RECT, ByVal wFormat As Long)
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Const DT_TOP = &H0
Private Const DT_LEFT = &H0
Private Const DT_CENTER = &H1 '垂直居中
Private Const DT_RIGHT = &H2
Private Const DT_VCENTER = &H4 '水平居中
Private Const DT_BOTTOM = &H8
Private Const DT_WORDBREAK = &H10
Private Const DT_SINGLELINE = &H20
Private Const DT_NOPREFIX = &H800 '取消“&”的下划线属性
Private Const DT_END_ELLIPSIS& = &H8000&
Private Const DT_MODIFYSTRING& = &H10000
Private Sub Command1_Click()
Dim str As String
Dim myRect As RECT
myRect.Left = 0
myRect.Top = 0
myRect.Right = 200
myRect.Bottom = 47
str = "你好,你看到的是DrawText()函数在窗体上绘制的文字,举行区域规格为200 * 50, top=0,left=0 由于本段文字太长,超出矩形区域的边界,不能显示的字符作...表示"
PrnPram = DT_LEFT Or DT_WORDBREAK Or DT_END_ELLIPSIS
Call DrawText(Form1.hDC, ByVal str, -1, myRect, PrnPram)
End Sub
- 深圳市一键一家网络科技有限公司官方网址:http://www.songhu9.com.cn
- QQ:316675593,电话号码:19807655856
- 业务范围:公司网站建设、管理软件研发、软件网站二次开发、400电话、电商平台研发、公众号研发!
- 免责申明:本站内容均来源于网络,版权归原创所有,如有任何版权方面的问题,请与我们联系处理!