找回密码
 加入
搜索
查看: 2652|回复: 6

[AU3基础] 循环的按钮【解决】

  [复制链接]
发表于 2010-5-13 01:36:19 | 显示全部楼层 |阅读模式
本帖最后由 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[6]
        For $i = 2 To ubound($button)-1
                Select
                        Case $Button[$i-1]
                                MsgBox(0,"","您点击了")
                EndSelect
        Next 
        
EndSwitch

WEnd
循环的按钮。像我这样的源码,怎么写呢?

评分

参与人数 1金钱 +10 收起 理由
afan + 10 感谢主动将修改帖子分类为[已解决],请继续 ...

查看全部评分

发表于 2010-5-13 02:09:51 | 显示全部楼层
创建时先定义数组变量
Dim $Button[6]
$Button[0] = GUICtrlCreateButton("Button1", 32, 24, 75, 25)
$Button[1] = GUICtrlCreateButton(xxx)
...
$Button[5] = GUICtrlCreateButton(xxx)

评分

参与人数 1金钱 +10 贡献 +10 收起 理由
116154801 + 10 + 10

查看全部评分

发表于 2010-5-13 02:12:29 | 显示全部楼层
本帖最后由 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[8]
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

评分

参与人数 1金钱 +10 贡献 +10 收起 理由
116154801 + 10 + 10

查看全部评分

发表于 2010-5-13 07:29:08 | 显示全部楼层
$hGUI = GUICreate("", 400, 300)
Local $aButton[6]
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[0] To $aButton[5]
                Msgbox(0, '', "Button " & $iMsg - 2)
        EndSwitch
WEnd

评分

参与人数 1金钱 +10 收起 理由
116154801 + 10

查看全部评分

发表于 2010-5-13 09:11:31 | 显示全部楼层
本帖最后由 水木子 于 2010-5-13 09:25 编辑

哇噻!楼主幸福哦!一个问题引来3位大师帮忙解决,羡慕啊!
而3位大师给出的问题也是非常精炼的,尤其是P版,一道简单的问题,他总是能用意想不到的思路解决。
每次都能从各位大师的代码中学习到很好的编写语法、逻辑和思路。
 楼主| 发表于 2010-5-13 10:15:21 | 显示全部楼层
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Local $Button[6]
#Region ### START Koda GUI section ### Form=D:\Backup\桌面\Form1.kxf
$Form1 = GUICreate("窗体1", 413, 305, 302, 218)
$Button[1] = GUICtrlCreateButton("Button1", 32, 24, 75, 25)
$Button[2] = GUICtrlCreateButton("Button2", 146, 23, 75, 25)
$Button[3] = GUICtrlCreateButton("Button3", 246, 25, 75, 25)
$Button[4] = GUICtrlCreateButton("Button4", 35, 84, 75, 25)
$Button[5] = 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[1] To $Button[5]
                                        MsgBox(0,"","您点击了Button" & $nMsg - 2)

        
                EndSwitch

WEnd
谢谢大家。
嘿嘿,我也解决了。
发表于 2012-3-5 17:13:17 | 显示全部楼层
好东西,学习了
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-9-30 19:38 , Processed in 0.093117 second(s), 20 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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