永发信息网

vb drawtext怎样设置字体

答案:1  悬赏:70  手机版
解决时间 2021-03-20 14:39
vb drawtext怎样设置字体
最佳答案
下面是个例子:
Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
Private Declare Function GetStockObject Lib "gdi32" (ByVal nIndex As Long) As Long
Private Declare Function GetObject Lib "gdi32" Alias "GetObjectA" (ByVal hObject As Long, ByVal nCount As Long, lpObject As LOGFONT) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Private Declare Function CreateFontIndirect Lib "gdi32" Alias "CreateFontIndirectA" (lpLogFont As LOGFONT) As Long
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) As Long
Private Const SYSTEM_FONT = 13
Private Const LF_FACESIZE = 32
Private Type LOGFONT
        lfHeight As Long
        lfWidth As Long
        lfEscapement As Long
        lfOrientation As Long
        lfWeight As Long
        lfItalic As Byte
        lfUnderline As Byte
        lfStrikeOut As Byte
        lfCharSet As Byte
        lfOutPrecision As Byte
        lfClipPrecision As Byte
        lfQuality As Byte
        lfPitchAndFamily As Byte
        lfFaceName(1 To LF_FACESIZE) As Byte
End Type
Private Type RECT
        Left As Long
        Top As Long
        Right As Long
        Bottom As Long
End Type


Private Sub Command1_Click()  '点击Command1运行
Dim ofont As Long, nfont As Long
Dim lf As LOGFONT, r As RECT
Dim s As String
ofont = SelectObject(Picture1.hdc, GetStockObject(SYSTEM_FONT)) '获取Picture1的当前字体对象
GetObject ofont, Len(lf), lf '从字体对象中获取字体信息
lf.lfHeight = lf.lfHeight * 3  '字体扩大三倍(你可以自己改其他的)
nfont = CreateFontIndirect(lf)  '重新建立字体对象
ofont = SelectObject(Picture1.hdc, nfont) '替换Picture1中的字体对象
s = "123你好abc"  '要显示的文字
r.Left = 0 '此四行是设置要显示文字的区域范围(即整个Picture1)
r.Top = 0
r.Right = Picture1.ScaleWidth  15
r.Bottom = Picture1.ScaleHeight  15
DrawText Picture1.hdc, s, -1, r, 0  '显示文字
nfont = SelectObject(Picture1.hdc, ofont) '把Picture1的字体恢复为原来的
DeleteObject nfont  '删除新建的字体对象
End Sub
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
广源药店地址有知道的么?有点事想过去
单选题Ifyouhavenothingimportanttodo,you
医学上tomo什么意思
请教:投射电容屏边缘走线用不同金属材料的差
大学自主招生简章2017
我马上就中考了。前一段时间状态特别好,就是
拿着电放提单跟电放保函去哪里换单? 换单拿
单选题微量元素在生物体内虽很少,却是维持正
全球鹰远景左后车轮上面的钣金被刮花了,面积
在括号里填写相对应的词语。例:寒冷对冬天正
上海迪士尼乐园的门票管几天。
台客隆便利(文化路店)在哪里啊,我有事要去这
白天和黑夜,哪个好
刘家园小区一区(西1门)在哪里啊,我有事要去
你请我吃晚饭我请你吃早餐是什么意思
推荐资讯
成语例:鸟语花香
绵阳东辰2016小升初正录和预录的区别谁能告诉
承德在北京哪里
现在想买个悠悠球那个比较好,求推荐,并写一
我的26岁女房客又名天空之城 超级大坦克科比
在捷信贷了18000还了4个月一年多没还现在捷信
我在伙伴身上学到了什么
吉林市那有夫妻浴
求一些类似于翡翠花园这种的控制英雄,却不需
虚数的表示比如1+i是写成1+i还是i+1,是数
eclipse暗主题
内侧半月板后角见条状pdw1高信号是什么意思严
正方形一边上任一点到这个正方形两条对角线的
阴历怎么看 ?