找回密码
 加入
搜索
查看: 2602|回复: 3

[AU3基础] [已解决]请问如何让label控件的autosize属性生效

[复制链接]
发表于 2013-12-22 23:22:40 | 显示全部楼层 |阅读模式
本帖最后由 xiezhuoyi 于 2014-1-30 14:40 编辑

新手刚刚接触GUI,发现字符串太长时候LABEL的autosize属性没有生效,请教如何让他生效?
发表于 2013-12-23 00:15:44 | 显示全部楼层
Dim $str = "Label Text longth", $fntSize = 14
$GUI = GUICreate("Test", 300, 200)
$lb01= GUICtrlCreateLabel($str, 50, 50, StringLen($str) * $fntSize)
GUICtrlSetFont(-1, $fntSize)
GUISetState(@SW_SHOW)

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case -3
                        Exit
        EndSwitch
WEnd
 楼主| 发表于 2013-12-23 09:56:02 | 显示全部楼层
谢谢楼上的分享,您用的方法是先统计字符串长度再创建label控件,有没有方法改变已经创建好控件的长度呢?最近也刚刚在学习S大的自学教材,想做一个常用宏的程序加深影响,遇到这个问题!
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=E:\百度云同步盘\P\AU3\AU3脚本代码\系统常用宏.kxf
$Form1 = GUICreate("Form1", 774, 461, 192, 124)
$Label1 = GUICtrlCreateLabel("常用系统信息宏", 184, 16, 263, 39)
GUICtrlSetFont(-1, 26, 800, 0, "楷体")
GUICtrlSetColor(-1, 0x0000FF)
$Label2 = GUICtrlCreateLabel("@CPUArch:", 40, 72, 106, 28)
GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
$Label3 = GUICtrlCreateLabel("-", 216, 72, 100, 28)
GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xFF0000)
$Label4 = GUICtrlCreateLabel("@OSLang:", 40, 112, 97, 28)
GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
$Label5 = GUICtrlCreateLabel("-", 216, 112, 100, 28)
GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xFF0000)
$Label6 = GUICtrlCreateLabel("@OSBuild:", 40, 152, 97, 28)
GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
$Label7 = GUICtrlCreateLabel("-", 216, 152, 100, 28)
GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xFF0000)
$Label8 = GUICtrlCreateLabel("@ComputerName:", 40, 192, 162, 28)
GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
$Label9 = GUICtrlCreateLabel("-", 216, 192, 100, 28)
GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xFF0000)
$Label10 = GUICtrlCreateLabel("@IPAddress1:", 40, 232, 124, 28)
GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
$Label11 = GUICtrlCreateLabel("-", 216, 232, 100, 28)
GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xFF0000)
$Label12 = GUICtrlCreateLabel("@IPAddress3:", 40, 272, 124, 28)
GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
$Label13 = GUICtrlCreateLabel("-", 216, 272, 100, 28)
GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xFF0000)
$Label14 = GUICtrlCreateLabel("@DesktopHeight:", 40, 312, 151, 28)
GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
$Label15 = GUICtrlCreateLabel("-", 216, 312, 100, 28)
GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xFF0000)
$Label16 = GUICtrlCreateLabel("@DesktopDepth:", 40, 352, 146, 28)
GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
$Label17 = GUICtrlCreateLabel("-", 216, 352, 100, 28)
GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xFF0000)
$Label18 = GUICtrlCreateLabel("@OSArch:", 400, 72, 95, 28)
GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
$Label19 = GUICtrlCreateLabel("-", 576, 72, 100, 28)
GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xFF0000)
$Label20 = GUICtrlCreateLabel("@OSVersion:", 400, 112, 120, 28)
GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
$Label21 = GUICtrlCreateLabel("-", 576, 112, 100, 28)
GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xFF0000)
$Label22 = GUICtrlCreateLabel("@OSServicePack:", 400, 152, 159, 28)
GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
$Label23 = GUICtrlCreateLabel("-", 576, 152, 100, 28)
GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xFF0000)
$Label24 = GUICtrlCreateLabel("@UserName:", 400, 192, 118, 28)
GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
$Label25 = GUICtrlCreateLabel("-", 576, 192, 100, 28)
GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xFF0000)
$Label26 = GUICtrlCreateLabel("@IPAddress2:", 400, 232, 124, 28)
GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
$Label27 = GUICtrlCreateLabel("-", 576, 232, 100, 28)
GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xFF0000)
$Label28 = GUICtrlCreateLabel("@IPAddress4:", 400, 272, 124, 28)
GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
$Label29 = GUICtrlCreateLabel("-", 576, 272, 100, 28)
GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xFF0000)
$Label30 = GUICtrlCreateLabel("@DesktopWidth:", 400, 312, 144, 28)
GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
$Label31 = GUICtrlCreateLabel("-", 576, 312, 100, 28)
GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xFF0000)
$Label32 = GUICtrlCreateLabel("@DesktopRefresh:", 400, 352, 161, 28)
GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
$Label33 = GUICtrlCreateLabel("-", 576, 352, 100, 28)
GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xFF0000)
$Button1 = GUICtrlCreateButton("获取系统信息", 16, 416, 99, 25)
$Button2 = GUICtrlCreateButton("关闭", 136, 416, 75, 25)
$Label34 = GUICtrlCreateLabel("2013-12-22", 240, 424, 74, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $Button1
                        GUICtrlSetData($label3,@CPUArch)
                        GUICtrlSetData($label19,@OSArch)
                        GUICtrlSetData($label5,@OSLang)
                        GUICtrlSetData($label21,@OSVersion)
                        GUICtrlSetData($label7,@OSBuild)
                        GUICtrlSetData($label23,@OSServicePack)
                        GUICtrlSetData($label9,@ComputerName)
                        GUICtrlSetData($Label25,@UserName)
                        GUICtrlSetData($label11,@IPAddress1)
                        GUICtrlSetData($Label27,@IPAddress2)
                        GUICtrlSetData($label13,@IPAddress3)
                        GUICtrlSetData($Label29,@IPAddress4)
                        GUICtrlSetData($Label15,@DesktopHeight)
                        GUICtrlSetData($label31,@DesktopWidth)
                        GUICtrlSetData($label17,@DesktopDepth)
                        GUICtrlSetData($label33,@DesktopRefresh)
                        
                        
                Case $Button2
                        Exit
        EndSwitch
WEnd
发表于 2013-12-23 11:10:23 | 显示全部楼层
这个似乎需要先测量字符串的像素范围,相同的字符串在不同的字体、大小、字体的其它属性情况下,其像素范围都有可能不同。
记得具体测量比较繁琐,需要逐字测量,因为半角字符很多都占用不同的像素范围。
也可以使用 _WinAPI_GetTextExtentPoint32()
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-11-17 07:19 , Processed in 0.077154 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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