QPainter:drawText 文字大小怎么设置

 我来答
匿名用户
2017-08-12
展开全部
下面是个例子:PrivateDeclareFunctionSelectObjectLib"gdi32"(ByValhdcAsLong,ByValhObjectAsLong)AsLongPrivateDeclareFunctionGetStockObjectLib"gdi32"(ByValnIndexAsLong)AsLongPrivateDeclareFunctionGetObjectLib"gdi32"Alias"GetObjectA"(ByValhObjectAsLong,ByValnCountAsLong,lpObjectAsLOGFONT)AsLongPrivateDeclareFunctionDeleteObjectLib"gdi32"(ByValhObjectAsLong)AsLongPrivateDeclareFunctionCreateFontIndirectLib"gdi32"Alias"CreateFontIndirectA"(lpLogFontAsLOGFONT)AsLongPrivateDeclareFunctionDrawTextLib"user32"Alias"DrawTextA"(ByValhdcAsLong,ByVallpStrAsString,ByValnCountAsLong,lpRectAsRECT,ByValwFormatAsLong)AsLongPrivateConstSYSTEM_FONT=13PrivateConstLF_FACESIZE=32PrivateTypeLOGFONTlfHeightAsLonglfWidthAsLonglfEscapementAsLonglfOrientationAsLonglfWeightAsLonglfItalicAsBytelfUnderlineAsBytelfStrikeOutAsBytelfCharSetAsBytelfOutPrecisionAsBytelfClipPrecisionAsBytelfQualityAsBytelfPitchAndFamilyAsBytelfFaceName(1ToLF_FACESIZE)AsByteEndTypePrivateTypeRECTLeftAsLongTopAsLongRightAsLongBottomAsLongEndTypePrivateSubCommand1_Click()'点击Command1运行DimofontAsLong,nfontAsLongDimlfAsLOGFONT,rAsRECTDimsAsStringofont=SelectObject(Picture1.hdc,GetStockObject(SYSTEM_FONT))'获取Picture1的当前字体对象GetObjectofont,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=0r.Right=Picture1.ScaleWidth\15r.Bottom=Picture1.ScaleHeight\15DrawTextPicture1.hdc,s,-1,r,0'显示文字nfont=SelectObject(Picture1.hdc,ofont)'把Picture1的字体恢复为原来的DeleteObjectnfont'删除新建的字体对象EndSub
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式