找回密码
 加入
搜索
楼主: yhxhappy

[GUI管理] [已解决]如何计算 字符串 在 Label 占用的像素宽度

[复制链接]
发表于 2010-8-4 02:10:12 | 显示全部楼层
回复 15# yhxhappy


    不能自定义字体?yhxhappy兄究竟是以什么为依据才说出这句话的呢?
 楼主| 发表于 2010-8-4 10:21:00 | 显示全部楼层
本帖最后由 yhxhappy 于 2010-8-4 10:24 编辑

回复 16# pusofalse


P版再一次提醒了我,又重新验证发现把ListView和Label设置成一样的字体,计算出来的宽度非常准确,之前12楼的代码计算有误差可能是ListView和Label的默认字体或字号不一致导致的。
非常感谢P版的指点。
#include <GuiConstantsEx.au3>
#include <GuiListView.au3>

        
GUICreate("ListView Get String Width", 400, 150)
$hListView = GUICtrlCreateListView("", 2, 2, 394, 200, BitOR($LVS_SHOWSELALWAYS, $LVS_REPORT))
GUICtrlSetFont(-1, 12, 800, 0, "Arial")                                                ;设置字号及字体
GUICtrlSetState(-1, $GUI_HIDE)

$txt = "测试字符串A"
$width = _GUICtrlListView_GetStringWidth($hListView, $txt)

GUISetState()

GUICtrlCreateLabel($txt, 20, 50, $width, 18)
GUICtrlSetFont(-1, 12, 800, 0, "Arial")                                                ;设置字号及字体
GUICtrlSetBkColor(-1, 0xFFFFFF) 

GUICtrlCreateLabel("字符串 '" & $txt &"' 的像素宽度: "& $width, 20, 100, 400, 18)

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
GUIDelete()

评分

参与人数 1威望 +5 金钱 +30 收起 理由
pusofalse + 5 + 30

查看全部评分

发表于 2017-2-24 00:26:21 | 显示全部楼层
afan的更好的方法呢?
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-3-28 20:27 , Processed in 0.067798 second(s), 14 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表