循环的按钮【解决】
本帖最后由 116154801 于 2010-5-13 10:19 编辑#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=D:\Backup\桌面\Form1.kxf
$Form1 = GUICreate("窗体1", 413, 305, 302, 218)
$Button1 = GUICtrlCreateButton("Button1", 32, 24, 75, 25)
$Button2 = GUICtrlCreateButton("Button1", 146, 23, 75, 25)
$Button3 = GUICtrlCreateButton("Button1", 246, 25, 75, 25)
$Button4 = GUICtrlCreateButton("Button1", 35, 84, 75, 25)
$Button5 = GUICtrlCreateButton("Button1", 150, 82, 75, 25)
$Button6 = GUICtrlCreateButton("Button1", 246, 81, 75, 25)
$Label1 = GUICtrlCreateLabel("Label1", 88, 200, 36, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Dim $Button
For $i = 2 To ubound($button)-1
Select
Case $Button[$i-1]
MsgBox(0,"","您点击了")
EndSelect
Next
EndSwitch
WEnd
循环的按钮。像我这样的源码,怎么写呢? 创建时先定义数组变量
Dim $Button
$Button = GUICtrlCreateButton("Button1", 32, 24, 75, 25)
$Button = GUICtrlCreateButton(xxx)
...
$Button = GUICtrlCreateButton(xxx) 本帖最后由 lynfr8 于 2010-5-13 02:21 编辑
#include <GuiConstants.au3>
Opt("GUIOnEventMode", 1)
$Form1 = GUICreate("循环的按钮", 413, 305, 302, 218)
GUISetOnEvent($GUI_EVENT_CLOSE, "main")
Dim $Button
GUISetState()
For $i = 0 To 3
$Button[$i] = GUICtrlCreateButton("Button" & $i, 60, 20+30*($i), 121, 25, 0)
GUICtrlSetOnEvent($Button[$i], "main")
Next
For $i = 4 To 7
$Button[$i] = GUICtrlCreateButton("Button" & $i, 220, 20+30*($i), 121, 25, 0)
GUICtrlSetOnEvent($Button[$i], "main")
Next
While 1
Sleep(1000)
WEnd
Func main()
For $i = 0 To 7
Switch @GUI_CtrlId
Case $GUI_EVENT_CLOSE
Exit
Case $Button[$i]
MsgBox(4096, "", "你点击的是:Button" & $i)
EndSwitch
Next
EndFunc
善用搜索
http://www.autoitx.com/search.php?searchid=351&orderby=lastpost&ascdesc=desc&searchsubmit=yes
也可借鉴以下例子:
http://www.autoitx.com/forum.php?mod=redirect&goto=findpost&ptid=5781&pid=39101&fromuid=1003 $hGUI = GUICreate("", 400, 300)
Local $aButton
For $i = 0 To 5
$aButton[$i] = GUICtrlCreateButton("Button " & ($i + 1), 40, $i * 30 + 10, 80, 20)
Next
GUISetState()
While 1
$iMsg = GUIGetMsg()
Switch $iMsg
Case -3
Exit
Case $aButton To $aButton
Msgbox(0, '', "Button " & $iMsg - 2)
EndSwitch
WEnd 本帖最后由 水木子 于 2010-5-13 09:25 编辑
哇噻!楼主幸福哦!一个问题引来3位大师帮忙解决,羡慕啊!:face (26):
而3位大师给出的问题也是非常精炼的,尤其是P版,一道简单的问题,他总是能用意想不到的思路解决。
每次都能从各位大师的代码中学习到很好的编写语法、逻辑和思路。 #include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Local $Button
#Region ### START Koda GUI section ### Form=D:\Backup\桌面\Form1.kxf
$Form1 = GUICreate("窗体1", 413, 305, 302, 218)
$Button = GUICtrlCreateButton("Button1", 32, 24, 75, 25)
$Button = GUICtrlCreateButton("Button2", 146, 23, 75, 25)
$Button = GUICtrlCreateButton("Button3", 246, 25, 75, 25)
$Button = GUICtrlCreateButton("Button4", 35, 84, 75, 25)
$Button = GUICtrlCreateButton("Button5", 150, 82, 75, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button To $Button
MsgBox(0,"","您点击了Button" & $nMsg - 2)
EndSwitch
WEnd谢谢大家。
嘿嘿,我也解决了。 {:face (303):}好东西,学习了
页:
[1]