本帖最后由 yhxhappy 于 2010-8-3 10:18 编辑
P版说的我新手不明白,找了ListView的UDF,发现这个:
_GUICtrlListView_GetStringWidth($hWnd, $sString) 确定指定字符串的宽度
我试了发现在字符串是纯中文的情况下,宽度计算得很准确,但在中英文及标点混合的情况就偏差一些。#include <GuiConstantsEx.au3>
#include <GuiListView.au3>
GUICreate("ListView Get String Width", 400, 150)
$hListView = GUICtrlCreateListView("", 2, 2, 394, 200, BitOR($LVS_SHOWSELALWAYS, $LVS_REPORT))
GUICtrlSetState(-1, $GUI_HIDE)
$txt = "测试字符串ABCDEabcde,.=\/@#$%12345"
$width = _GUICtrlListView_GetStringWidth($hListView, $txt)
GUISetState()
GUICtrlCreateLabel($txt, 20, 50, $width, 15)
GUICtrlSetBkColor(-1, 0xFFFFFF)
MsgBox(4160, "", "字符串'" & $txt &"' 的像素宽度: "& $width)
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
GUIDelete()
|