多重Button 使用
感謝 afan 大大的源碼,因此稍作更改一下,剛好可以用到我另一個程式使用。#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
Opt('GUIOnEventMode', 1) ;啟用=1/禁用=0 OnEvent 事件函數通知
$number = InputBox("Button產生", "請輸入Button數量,不超過10個", "5", "")
If @error = 1Then 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 顶你一个!!!
页:
[1]