所以不要这样:
$Var1 = 'This is variable one :P'
$Var2 = 'This is variable two :P'
我想要这个(伪代码):
For $i = 1 to UBound($People)-1
**$var[$i]** = GUICtrlCreateCheckbox($var[$i], 24, $y, 200, 17)
$y = $y + 25
Next
有谁知道如何做到这一点?
根据Documentation - Intro - Arrays:
数组是包含一系列数据元素的变量。此变量中的每个元素都可以通过与数组中元素的位置相关的索引号访问 - 在 AutoIt 中,数组的第一个元素始终是元素 [0]。数组元素按定义的顺序存储并且可以排序。
动态复选框创建示例,将多个 checkbox-control 标识符分配给单个数组(未经测试,无错误检查):
#include <GUIConstantsEx.au3>
Global Const $g_iBoxStartX = 25
Global Const $g_iBoxStartY = 25
Global Const $g_iBoxWidth = 100
Global Const $g_iBoxHeight = 15
Global Const $g_iBoxSpace = 0
Global Const $g_iBoxAmount = Random(2, 20, 1)
Global Const $g_iBoxTextEx = $g_iBoxAmount -1
Global Const $g_sBoxTextEx = 'Your text here.'
Global Const $g_iWindDelay = 50
Global Const $g_iWinWidth = $g_iBoxWidth * 2
Global Const $g_iWinHeight = ($g_iBoxStartY * 2) + ($g_iBoxHeight * $g_iBoxAmount) + ($g_iBoxSpace * $g_iBoxAmount)
Global Const $g_sWinTitle = 'Example'
Global $g_hGUI
Global $g_aID
Main()
Func Main()
$g_hGUI = GUICreate($g_sWinTitle, $g_iWinWidth, $g_iWinHeight)
$g_aID = GUICtrlCreateCheckboxMulti($g_iBoxStartX, $g_iBoxStartY, $g_iBoxWidth, $g_iBoxHeight, $g_iBoxSpace, $g_iBoxAmount)
GUICtrlSetData($g_aID[$g_iBoxTextEx], $g_sBoxTextEx)
GUISetState(@SW_SHOW, $g_hGUI)
While Not (GUIGetMsg() = $GUI_EVENT_CLOSE)
Sleep($g_iWindDelay)
WEnd
Exit
EndFunc
Func GUICtrlCreateCheckboxMulti(Const $iStartX, Const $iStartY, Const $iWidth, Const $iHeight, Const $iSpace, Const $iAmount, Const $sTextTpl = 'Checkbox #%s')
Local $iYPosCur = 0
Local $sTextCur = ''
Local $aID[$iAmount]
For $i1 = 0 To $iAmount -1
$iYPosCur = $iStartY + ($iHeight * $i1) + ($iSpace * $i1)
$sTextCur = StringFormat($sTextTpl, $i1 +1)
$aID[$i1] = GUICtrlCreateCheckbox($sTextCur, $iStartX, $iYPosCur, $iWidth, $iHeight)
Next
Return $aID
EndFunc
-
GUICtrlCreateCheckboxMulti() 演示
-
Main() 演示单个元素的选择(使用 GUICtrlSetData() 更改其文本)。
- 根据需要调整常量(
$g_iBoxAmount 等)。