求高手解决哈,复选框在Func.....endFun里面怎么写(已解决)
本帖最后由 qsy666888 于 2018-3-21 16:38 编辑求高手解决哈,复选框在Func.....endFun里面哪个 Switch怎么写??#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Dim $text,$Button2,$Checkbox1,$Checkbox2,$Checkbox3,$Checkbox4,$Checkbox5,$Checkbox6,$Checkbox7,$Button1
fxk()
Func fxk()
Global $Form1 = GUICreate("Form1", 200, 178, -1, -1, BitOR($WS_SYSMENU, $WS_POPUP,$WS_SIZEBOX))
;GUISetBkColor(0xF4F7FC)
Global $Group1 = GUICtrlCreateGroup("", 5, 0, 189, 148)
Global $Checkbox1 = GUICtrlCreateCheckbox("全选", 16, 8, 97, 17)
Global $Checkbox2 = GUICtrlCreateCheckbox("居住", 16, 28, 97, 17)
Global $Checkbox3 = GUICtrlCreateCheckbox("商业", 16, 48, 97, 17)
Global $Checkbox4 = GUICtrlCreateCheckbox("公共", 16, 68, 97, 17)
Global $Checkbox5 = GUICtrlCreateCheckbox("交通", 16, 88, 97, 17)
Global $Checkbox6 = GUICtrlCreateCheckbox("工业", 16, 108, 97, 17)
Global $Checkbox7 = GUICtrlCreateCheckbox("其它", 16, 128, 97, 17)
Global $Button1 = GUICtrlCreateButton("确定", 54, 150, 60, 23)
GUICtrlSetOnEvent(-1, "Quding")
Global $Button2 = GUICtrlCreateButton("退出", 126, 150, 60, 23)
GUICtrlSetOnEvent(-1, "Form1Close")
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
EndFunc
Func Quding()
Switch $XXXX
Case $Button2
Exit
;Case $GUI_EVENT_PRIMARYDOWN
;_SendMessage($Form1, $WM_SYSCOMMAND, $SC_MOVE + $HTCAPTION, 0)
Case $Checkbox1
If BitAND(GUICtrlRead($Checkbox1), $GUI_CHECKED) Then
GUICtrlSetState($Checkbox2, $gui_checked)
GUICtrlSetState($Checkbox3, $gui_checked)
GUICtrlSetState($Checkbox4, $gui_checked)
GUICtrlSetState($Checkbox5, $gui_checked)
GUICtrlSetState($Checkbox6, $gui_checked)
GUICtrlSetState($Checkbox7, $gui_checked)
$text = ' 居住 商业 公共 交通 工业 其它'
Else
GUICtrlSetState($Checkbox2, $gui_unchecked)
GUICtrlSetState($Checkbox3, $gui_unchecked)
GUICtrlSetState($Checkbox4, $gui_unchecked)
GUICtrlSetState($Checkbox5, $gui_unchecked)
GUICtrlSetState($Checkbox6, $gui_unchecked)
GUICtrlSetState($Checkbox7, $gui_unchecked)
$text = ''
EndIf
Case $Checkbox2
If BitAND(GUICtrlRead($Checkbox2), $GUI_CHECKED) Then
$text0 = '居住'
$text = $text&' '&$text0
Else
$text = StringReplace($text, " 居住", "")
EndIf
Case $Checkbox3
If BitAND(GUICtrlRead($Checkbox3), $GUI_CHECKED) Then
$text0 = '商业'
$text = $text&' '&$text0
Else
$text = StringReplace($text, " 商业", "")
EndIf
Case $Checkbox4
If BitAND(GUICtrlRead($Checkbox4), $GUI_CHECKED) Then
$text0 = '公共'
$text = $text&' '&$text0
Else
$text = StringReplace($text, " 公共", "")
EndIf
Case $Checkbox5
If BitAND(GUICtrlRead($Checkbox5), $GUI_CHECKED) Then
$text0 = '交通'
$text = $text&' '&$text0
Else
$text = StringReplace($text, " 交通", "")
EndIf
Case $Checkbox6
If BitAND(GUICtrlRead($Checkbox6), $GUI_CHECKED) Then
$text0 = '工业'
$text = $text&' '&$text0
Else
$text = StringReplace($text, " 工业", "")
EndIf
Case $Checkbox7
If BitAND(GUICtrlRead($Checkbox7), $GUI_CHECKED) Then
$text0 = '其它'
$text = $text&' '&$text0
Else
$text = StringReplace($text, " 其它", "")
EndIf
Case $Button1
MsgBox(0,'',$text)
EndSwitch
EndFunc
Func Form1Close()
Exit
EndFunc
恕刪
本帖最后由 kk_lee69 于 2018-3-21 15:51 编辑#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Dim $text,$Button2,$Checkbox1,$Checkbox2,$Checkbox3,$Checkbox4,$Checkbox5,$Checkbox6,$Checkbox7,$Button1
Opt("GUIOnEventMode", 1)
fxk()
While 1
SLEEP(10)
WEnd
Func fxk()
Global $Form1 = GUICreate("Form1", 200, 178, -1, -1, BitOR($WS_SYSMENU, $WS_POPUP,$WS_SIZEBOX))
;GUISetBkColor(0xF4F7FC)
Global $Group1 = GUICtrlCreateGroup("", 5, 0, 189, 148)
Global $Checkbox1 = GUICtrlCreateCheckbox("全?", 16, 8, 97, 17)
Global $Checkbox2 = GUICtrlCreateCheckbox("居住", 16, 28, 97, 17)
Global $Checkbox3 = GUICtrlCreateCheckbox("商?", 16, 48, 97, 17)
Global $Checkbox4 = GUICtrlCreateCheckbox("公共", 16, 68, 97, 17)
Global $Checkbox5 = GUICtrlCreateCheckbox("交通", 16, 88, 97, 17)
Global $Checkbox6 = GUICtrlCreateCheckbox("工?", 16, 108, 97, 17)
Global $Checkbox7 = GUICtrlCreateCheckbox("其它", 16, 128, 97, 17)
Global $Button1 = GUICtrlCreateButton("确定", 54, 150, 60, 23)
GUICtrlSetOnEvent(-1, "Quding")
Global $Button2 = GUICtrlCreateButton("退出", 126, 150, 60, 23)
GUICtrlSetOnEvent(-1, "Form1Close")
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
EndFunc
Func Quding()
Switch $XXXX
Case $Button2
Exit
;Case $GUI_EVENT_PRIMARYDOWN
;_SendMessage($Form1, $WM_SYSCOMMAND, $SC_MOVE + $HTCAPTION, 0)
Case $Checkbox1
If BitAND(GUICtrlRead($Checkbox1), $GUI_CHECKED) Then
GUICtrlSetState($Checkbox2, $gui_checked)
GUICtrlSetState($Checkbox3, $gui_checked)
GUICtrlSetState($Checkbox4, $gui_checked)
GUICtrlSetState($Checkbox5, $gui_checked)
GUICtrlSetState($Checkbox6, $gui_checked)
GUICtrlSetState($Checkbox7, $gui_checked)
$text = ' 居住 商? 公共 交通 工? 其它'
Else
GUICtrlSetState($Checkbox2, $gui_unchecked)
GUICtrlSetState($Checkbox3, $gui_unchecked)
GUICtrlSetState($Checkbox4, $gui_unchecked)
GUICtrlSetState($Checkbox5, $gui_unchecked)
GUICtrlSetState($Checkbox6, $gui_unchecked)
GUICtrlSetState($Checkbox7, $gui_unchecked)
$text = ''
EndIf
Case $Checkbox2
If BitAND(GUICtrlRead($Checkbox2), $GUI_CHECKED) Then
$text0 = '居住'
$text = $text&' '&$text0
Else
$text = StringReplace($text, " 居住", "")
EndIf
Case $Checkbox3
If BitAND(GUICtrlRead($Checkbox3), $GUI_CHECKED) Then
$text0 = '商?'
$text = $text&' '&$text0
Else
$text = StringReplace($text, " 商?", "")
EndIf
Case $Checkbox4
If BitAND(GUICtrlRead($Checkbox4), $GUI_CHECKED) Then
$text0 = '公共'
$text = $text&' '&$text0
Else
$text = StringReplace($text, " 公共", "")
EndIf
Case $Checkbox5
If BitAND(GUICtrlRead($Checkbox5), $GUI_CHECKED) Then
$text0 = '交通'
$text = $text&' '&$text0
Else
$text = StringReplace($text, " 交通", "")
EndIf
Case $Checkbox6
If BitAND(GUICtrlRead($Checkbox6), $GUI_CHECKED) Then
$text0 = '工?'
$text = $text&' '&$text0
Else
$text = StringReplace($text, " 工?", "")
EndIf
Case $Checkbox7
If BitAND(GUICtrlRead($Checkbox7), $GUI_CHECKED) Then
$text0 = '其它'
$text = $text&' '&$text0
Else
$text = StringReplace($text, " 其它", "")
EndIf
Case $Button1
MsgBox(0,'',$text)
EndSwitch
EndFunc
Func Form1Close()
Exit
EndFunc 回复 2# kk_lee69
感谢 kk_lee69 大侠的回复,我表达的是复选框在func.....endfunc里面怎么写,就是 Switch $XXXX ,$xxxx这个该怎么写 本帖最后由 kk_lee69 于 2018-3-21 15:54 编辑
回复 3# qsy666888
已經修正
你的問題跟複選框 無關你的問題只是 GUI 的消息模式 與循環模式的問題 回复 4# kk_lee69
是能够显示,但复选框的功能好像没有反应了,我勾选全选的时候,只有全选的一项被选上,对其它复选框没有反应 回复 4# kk_lee69
觉得把GUI主题写在一个FUNC里 基本所有控件变量都要定义成全局变量。 回复 5# qsy666888
Global $Button2 = GUICtrlCreateButton("退出", 126, 150, 60, 23)
GUICtrlSetOnEvent(-1, "Form1Close")
這兩行是你寫的 程式能夠告訴我
你為何要加入
GUICtrlSetOnEvent(-1, "Form1Close")
這一行嗎用意是甚麼用途是甚麼
那麼你就會知道 為何 其他的按鈕沒作用 本帖最后由 heroxianf 于 2018-3-21 16:12 编辑
回复 5# qsy666888
复选框选中状态需要你自己仔细设置了。也要对 $Checkbox1 添加事件的 GUICtrlSetOnEvent(-1, "Quding") 回复 6# heroxianf
我倒覺得 這點是沒有辦法的當初我也為了這個煩惱過
我喜歡把一個一個GUI 寫在一個一個的 FUNC 裡面 要用的時候才呼叫出來
後來覺得消息模式 比較方便但是缺點就是 幾乎所有的控件 都得變成全局
聽 大老 說 應該是不用擔心定義太多的 全局 變數
所以也就這樣繼續用了 回复 7# kk_lee69
大侠哈,我就是注释掉,还是不行 回复 9# kk_lee69
我这里运行出错,不知道他这句是什么原理 If BitAND(GUICtrlRead($Checkbox1), $GUI_CHECKED) Then
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Opt("GUIOnEventMode", 1) ;事件模式开启
fxk()
Func fxk()
Local $Form1, $text, $Button1, $Button2, $Checkbox1, $Checkbox2, $Checkbox3, $Checkbox4, $Checkbox5, $Checkbox6, $Checkbox7, $Group1
$Form1 = GUICreate("Form1", 200, 178, -1, -1)
$Group1 = GUICtrlCreateGroup("", 5, 0, 189, 148)
$Checkbox1 = GUICtrlCreateCheckbox("全选", 16, 8, 97, 17)
GUICtrlSetOnEvent(-1, "Quding")
$Checkbox2 = GUICtrlCreateCheckbox("居住", 16, 28, 97, 17)
$Checkbox3 = GUICtrlCreateCheckbox("商业", 16, 48, 97, 17)
$Checkbox4 = GUICtrlCreateCheckbox("公共", 16, 68, 97, 17)
$Checkbox5 = GUICtrlCreateCheckbox("交通", 16, 88, 97, 17)
$Checkbox6 = GUICtrlCreateCheckbox("工业", 16, 108, 97, 17)
$Checkbox7 = GUICtrlCreateCheckbox("其它", 16, 128, 97, 17)
$Button1 = GUICtrlCreateButton("确定", 54, 150, 60, 23)
GUICtrlSetOnEvent(-1, "Quding")
$Button2 = GUICtrlCreateButton("退出", 126, 150, 60, 23)
GUICtrlSetOnEvent(-1, "Quding")
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
EndFunc ;==>fxk
While 1
Sleep(100)
WEnd
Func Quding()
Local $Form1, $text, $Button1, $Button2, $Checkbox1, $Checkbox2, $Checkbox3, $Checkbox4, $Checkbox5, $Checkbox6, $Checkbox7, $Group1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $Button2
Exit
Case $Checkbox1
If BitAND(GUICtrlRead($Checkbox1), $GUI_CHECKED) Then
GUICtrlSetState($Checkbox2, $gui_checked)
GUICtrlSetState($Checkbox3, $gui_checked)
GUICtrlSetState($Checkbox4, $gui_checked)
GUICtrlSetState($Checkbox5, $gui_checked)
GUICtrlSetState($Checkbox6, $gui_checked)
GUICtrlSetState($Checkbox7, $gui_checked)
$text = ' 居住 商业 公共 交通 工业 其它'
Else
GUICtrlSetState($Checkbox2, $gui_unchecked)
GUICtrlSetState($Checkbox3, $gui_unchecked)
GUICtrlSetState($Checkbox4, $gui_unchecked)
GUICtrlSetState($Checkbox5, $gui_unchecked)
GUICtrlSetState($Checkbox6, $gui_unchecked)
GUICtrlSetState($Checkbox7, $gui_unchecked)
$text = ''
EndIf
EndSwitch
EndFunc ;==>Quding
回复 8# heroxianf
对 $Checkbox1 添加事件的 GUICtrlSetOnEvent(-1, "Quding"),我添加了,但点击复选框,对其它复选框没有反应,我纳闷,不知道问题出在哪里? 回复 10# qsy666888
所以我說了 你對於 消息模式 跟循環模式 不懂
你的 checkBOX 根本不會產生任何作用
而你的 確定 跟 退出可以有反應 是因為你加了那行字
才會有反應不信你把退出的 那行 註釋掉你連退出都無法 回复 9# kk_lee69
主要是想点击第一个窗口的按钮,弹出复选框,再把复选框的值返回给第一个窗口Input控件里面,如果不用func,那怎么弄哈 回复 14# qsy666888
請先仔細研讀
http://www.autoit3.cn/forum.php?mod=viewthread&tid=476&from=favorites
對你幫助很大的
页:
[1]
2