找回密码
 加入
搜索
查看: 1604|回复: 4

[网络通信] 如何 Case批量生成的button控件

  [复制链接]
发表于 2018-10-20 15:06:17 | 显示全部楼层 |阅读模式

各位好,今天想请教下关于如何case批量生成button的问题,如源码
尝试过的方法:之前有看到过A大发表关于 鼠标移动上去 标签控件变色的的方法。 AdlibRegister + GUIGetCursorInfo 实现,所以抄了一下,发现不行。不知道如何在 Case上写表达式。当我鼠标移动上去之后,通过 返回的元素[4] 我能知道当前我鼠标位置上的控件的ID,再然后思路就断了。


目前主要难点: 不会使用case 涵盖所有这样的Button。 若Case $Button[$i] 也只能是最后一个 $i 生成的button有用。


想要达到的目的: 我点击每一个button 都能执行相同的操作, 比如点击任意一个button都显示 Msgbox(0,0,1)  

还请有遇到过类似情况的前辈指点。


#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 615, 437, 192, 124)
Local $Button[11]
Local $i =1
Do
$Button[$i] = GUICtrlCreateButton("Button1", 312, 68+40*$i, 105, 25)
$i +=1
Until $i = 9
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit

        EndSwitch
WEnd


本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
发表于 2018-10-20 16:39:17 | 显示全部楼层
zqjares 发表于 2018-10-20 16:27
感谢A大的指导,非常有用,但是也存在了问题。把难度升级一下, 我也是第一次知道Case可以 加to ,我理解 ...

用事件模式,更简单
Opt('GUIOnEventMode', 1)

GUICreate('', 400)
GUISetOnEvent(-3, '_Exit')
Local $Button[9], $Checkbox[9], $i = 1
For $i = 1 To 8
        $Button[$i] = GUICtrlCreateButton('Button ' & $i, 50, 5 + 40 * $i, 120, 25)
        GUICtrlSetOnEvent(-1, '_Test')
        $Checkbox[$i] = GUICtrlCreateCheckbox('Button ' & $i, 250, 5 + 40 * $i, 120, 25)
Next
GUISetState(@SW_SHOW)

While 1
        Sleep(1000)
WEnd

Func _Exit()
        Exit
EndFunc   ;==>_Exit
Func _Test()
        MsgBox(0, '', GUICtrlRead(@GUI_CtrlId))
EndFunc   ;==>_Test
发表于 2018-10-20 15:14:22 | 显示全部楼层
GUICreate('', 220)
Local $Button[9], $i = 1
Do
        $Button[$i] = GUICtrlCreateButton('Button ' & $i, 50, 5 + 40 * $i, 120, 25)
        $i += 1
Until $i = 9
GUISetState(@SW_SHOW)

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case -3
                        Exit
                Case $Button[1] To $Button[8]
                        MsgBox(0, '', GUICtrlRead($nMsg))
        EndSwitch
WEnd
 楼主| 发表于 2018-10-20 16:27:12 | 显示全部楼层
afan 发表于 2018-10-20 15:14
[au3]GUICreate('', 220)
Local $Button[9], $i = 1
Do

感谢A大的指导,非常有用,但是也存在了问题。把难度升级一下, 我也是第一次知道Case可以 加to ,我理解为这样的话就是 比如 控件范围是 10~49  那么这其中的所有控件都受控制。而不仅限于 Button控件。
如修改过后的 源码:  这样子 Checkbox的控件也会执行跟 button一样的动作,可否只有button控件执行呢。

GUICreate('', 400)
Local $Button[10], $i = 1
Local $Checkbox[10], $i = 1
Do
        $Button[$i] = GUICtrlCreateButton('Button ' & $i, 50, 5 + 40 * $i, 120, 25)
                $Checkbox[$i] = GUICtrlCreateCheckbox('Button ' & $i, 250, 5 + 40 * $i, 120, 25)
        $i += 1
Until $i = 9
GUISetState(@SW_SHOW)

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case -3
                        Exit
                Case $Button[1] To $Button[8]
                        MsgBox(0, '', GUICtrlRead($nMsg))
        EndSwitch
WEnd
发表于 2018-10-23 23:39:33 | 显示全部楼层
可以搜索A大的文章,有一个批量按钮自动排列创建的帖子。
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-4-20 02:34 , Processed in 0.074040 second(s), 21 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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