找回密码
 加入
搜索
查看: 1367|回复: 1

[转贴] 多重Button 使用

[复制链接]
发表于 2020-10-31 11:36:49 | 显示全部楼层 |阅读模式
感謝 afan 大大的源碼,因此稍作更改一下,剛好可以用到我另一個程式使用。
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>

Opt('GUIOnEventMode', 1) ;啟用=1/禁用=0 OnEvent 事件函數通知

$number = InputBox("Button產生", "請輸入Button數量,不超過10個", "5", "")
If @error = 1  Then Exit
$number = Int($number)
If $number > 10 Then
        MsgBox(0,"輸入錯誤","button數量超過10個,即將關閉")
        Exit
EndIf

If $number <= 5 Then
        $GuiView = GUICreate('多重BUTTON', 250,250) ;建立GUI視窗,並建立視窗句柄
Else
        $GuiView = GUICreate('多重BUTTON', 400,250) ;建立GUI視窗,並建立視窗句柄
EndIf

GUISetOnEvent($GUI_EVENT_CLOSE, '_Exit') ;收到視窗關閉鈕時呼叫_EXIT函數離開

Local $Button[$number + 1]
$ButtonHeight = 30 ;設定第一個Button頂距
For $i = 1 To $number
        If $i <= 5 Then
                $Button[$i] = GUICtrlCreateButton('Button ' & $i, 70, $ButtonHeight, 100, 25)
                GUICtrlSetOnEvent(-1, '_Button_Read')
                $ButtonHeight = (40 * $i) + 30 ;開始設定第二個Button頂距,注意後面值需配合第一個Button頂距初始值,例設30 則該行也設一樣
        Else
                If $i = 6 Then ;當設定Button 6 時設定第二排後的Button
                        $ButtonHeight = 30
                        $Button[$i] = GUICtrlCreateButton('Button ' & $i, 200, $ButtonHeight, 100, 25)
                        GUICtrlSetOnEvent(-1, '_Button_Read')
                Else
                        $ButtonHeight = (40 * ($i-6)) + 30 ;開始設定第7個後Button頂距,注意後面值需配合第6個Button頂距初始值,例設30 則該行也設一樣
                        $Button[$i] = GUICtrlCreateButton('Button ' & $i, 200, $ButtonHeight, 100, 25)
                        GUICtrlSetOnEvent(-1, '_Button_Read')
                EndIf
        EndIf
Next
GUISetState(@SW_SHOW,$GuiView)

While 1
        Sleep(1000)
WEnd

Func _Exit() ;視窗關閉
        Exit
EndFunc
Func _Button_Read()
        MsgBox(0, '', GUICtrlRead(@GUI_CtrlId))
EndFunc
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-5-4 02:31 , Processed in 0.068170 second(s), 19 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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