找回密码
 加入
搜索
查看: 1251|回复: 2

怎么用循环表达哪个按钮被点击?

[复制链接]
发表于 2009-3-16 18:01:28 | 显示全部楼层 |阅读模式
#include <Array.au3>
#include <EditConstants.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

Global $Row_a = 5, $Row_b = 5, $ButTxt1[33]
$Form1 = GUICreate("Form1", 200, 200, -1, -1)
$k = 1
For $i = 0 To $Row_a - 1
        For $j = 0 To $Row_b - 1
                $ButTxt1[$k] = GUICtrlCreateButton($k, 6 + 36 * $i, 6 + 36 * $j, 33, 33)
                $k = $k + 1
        Next
Next
GUISetState(@SW_SHOW)
While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $ButTxt1[1]
                        Find1()
                Case $ButTxt1[2]
                        Find2()
                Case $ButTxt1[3]
                        Find3()
                Case $ButTxt1[4]
                        Find4()
                Case $ButTxt1[5]
                        Find5()
        EndSwitch
WEnd

Func Find1()
        $ShowNo = GUICtrlRead($ButTxt1[1])
        MsgBox(0, "", $ShowNo)
EndFunc   ;==>Find1

Func Find2()
        $ShowNo = GUICtrlRead($ButTxt1[2])
        MsgBox(0, "", $ShowNo)
EndFunc   ;==>Find2

Func Find3()
        $ShowNo = GUICtrlRead($ButTxt1[3])
        MsgBox(0, "", $ShowNo)
EndFunc   ;==>Find3

Func Find4()
        $ShowNo = GUICtrlRead($ButTxt1[4])
        MsgBox(0, "", $ShowNo)
EndFunc   ;==>Find4

Func Find5()
        $ShowNo = GUICtrlRead($ButTxt1[5])
        MsgBox(0, "", $ShowNo)
EndFunc   ;==>Find5


点击某个按钮会显示该按钮上的值。
用循环。


[ 本帖最后由 qst 于 2009-3-17 17:10 编辑 ]
发表于 2009-3-17 11:52:59 | 显示全部楼层

Global $Row_a = 5, $Row_b = 5, $ButTxt1[33]
$Form1 = GUICreate("Form1", 200, 200, -1, -1)
$k = 1
For $i = 0 To $Row_a - 1
        For $j = 0 To $Row_b - 1
                $ButTxt1[$k] = GUICtrlCreateButton($k, 6 + 36 * $i, 6 + 36 * $j, 33, 33)
                $k = $k + 1
        Next
Next
GUISetState(@SW_SHOW)
While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case -3
                        Exit
                Case $ButTxt1[1] To $ButTxt1[25]
                        For $i = 1 To 25
                                If $nMsg = $ButTxt1[$i] Then MsgBox(0, 0, '你按下了:' & GUICtrlRead($ButTxt1[$i]) & '号按钮')
                        Next
        EndSwitch
WEnd

评分

参与人数 3金钱 +20 贡献 +5 收起 理由
大绯狼 + 10 + 5 真后悔以前没看见!
qst + 5
顽固不化 + 5 优质回帖

查看全部评分

发表于 2009-3-17 12:05:01 | 显示全部楼层
学习了 case to
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-5-19 07:36 , Processed in 0.081645 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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