Example()
Func Example()
; 初始化GUI
Local $hWnd = GUICreate("按钮创建示例", 400, 300)
GUISetState(@SW_SHOW)
Local $buttonWidth = 100 ; 按钮宽度
Local $buttonHeight = 30 ; 按钮高度
Local $buttonPadding = 20 ; 按钮之间的间距
Local $currentX = $buttonPadding ; 初始化X坐标为按钮间距
Local $currentY = $buttonPadding ; 初始化Y坐标为按钮间距
Local $buttonsPerRow = 3 ; 每行按钮数量
Local $buttonCount = 0 ; 按钮计数器
; 假设我们要创建9个按钮
Local $totalButtons = 9
Local $buttonText, $aButton[$totalButtons]
; 循环创建按钮
For $i = 1 To $totalButtons
$buttonCount += 1
$buttonText = "按钮 " & $i
; 检查是否需要换行(即当前按钮是否超出每行按钮数量)
If Mod($buttonCount, $buttonsPerRow) = 1 Then
$currentX = $buttonPadding ; 重置X坐标到起始位置
$currentY += $buttonHeight + $buttonPadding ; 增加Y坐标以开始新的一行
EndIf
; 创建按钮及进度条并设置其位置
$aButton[$i - 1] = GUICtrlCreateButton($buttonText, $currentX, $currentY, $buttonWidth, $buttonHeight)
GUICtrlCreateProgress($currentX, $currentY + $buttonHeight, $buttonWidth, 10) ;进度条
; 增加X坐标以准备放置下一个按钮
$currentX += $buttonWidth + $buttonPadding
Next
; Loop until the user exits.
Local $iMsg
While 1
$iMsg = GUIGetMsg()
Switch $iMsg
Case -3
ExitLoop
Case $aButton[0] To $aButton[$totalButtons - 1]
GUICtrlSetData($iMsg + 1, 100)
EndSwitch
WEnd
EndFunc ;==>Example
|