函数参考


_GUICtrlButton_GetIdealSize

获取按钮适配文本和图像的最佳尺寸

#include <GuiButton.au3>
_GUICtrlButton_GetIdealSize($hWnd)

参数

$hWnd 控件的控件ID/句柄

返回值

返回包含下列形式的数组:
        [0] - 最佳宽度
        [1] - 最佳高度

注意/说明

最低操作系统 - Windows XP.

相关

_GUICtrlButton_SetSize

详情参考

在MSDN中搜索


示例/演示


#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiButton.au3>
#include <GuiImageList.au3>

Global $iMemo

_Main()

Func _Main()
    Local $hImage, $btn, $aIdealSize

    GUICreate("Buttons", 400, 400)
    $iMemo = GUICtrlCreateEdit("", 119, 10, 276, 374, $WS_VSCROLL)
    GUICtrlSetFont($iMemo, 9, 400, 0, "Courier New")

    $hImage = _GUIImageList_Create(32, 32, 5, 3, 6)
    For $x = 6 To 11
        _GUIImageList_AddIcon($hImage, "shell32.dll", $x, True)
    Next

    $btn = GUICtrlCreateButton("Button1", 10, 10, 90, 50)
    _GUICtrlButton_SetImageList($btn, $hImage)

    GUISetState()

    $aIdealSize = _GUICtrlButton_GetIdealSize($btn)
    MemoWrite("Button1 Ideal width: " & $aIdealSize[0] & " height: " & $aIdealSize[1])

    Sleep(3000)

    MemoWrite(StringFormat("Set Size: %s", _GUICtrlButton_SetSize($btn, $aIdealSize[0], $aIdealSize[1])))

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
        EndSwitch
    WEnd

    Exit
EndFunc   ;==>_Main

; 写入一行到 memo 控件
Func MemoWrite($sMessage)
    GUICtrlSetData($iMemo, $sMessage & @CRLF, 1)
EndFunc   ;==>MemoWrite