找回密码
 加入
搜索
楼主: qsy666888

[AU3基础] 求高手解决哈,复选框在Func.....endFun里面怎么写(已解决)

 火.. [复制链接]
 楼主| 发表于 2018-3-21 16:21:17 | 显示全部楼层
回复 13# kk_lee69

我注释掉了业没有反应
发表于 2018-3-21 16:21:31 | 显示全部楼层
本帖最后由 heroxianf 于 2018-3-21 16:22 编辑

回复 12# qsy666888

注意放置的先后顺序


#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

fxk()

Opt("GUIOnEventMode", 1) ;事件模式开启

Global $Form1, $text, $Button1, $Button2, $Checkbox1, $Checkbox2, $Checkbox3, $Checkbox4, $Checkbox5, $Checkbox6, $Checkbox7

Func fxk() ;你这个命名法要被老大说的
        $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 $nMsg
        $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 = ' 居住 商业 公共 交通 工业 其它'
                                MsgBox(0, 0, $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 = ''
                                MsgBox(0, 0, $text)
                        EndIf
        EndSwitch
EndFunc   ;==>Quding


发表于 2018-3-21 16:30:03 | 显示全部楼层
是不是这样
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Dim $text, $Button2, $Checkbox1, $Checkbox2, $Checkbox3, $Checkbox4, $Checkbox5, $Checkbox6, $Checkbox7, $Button1
fxk()
Quding()
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   ;==>fxk

Func Quding()
        While 1
                Switch GUIGetMsg()
                        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
        WEnd
EndFunc   ;==>Quding

Func Form1Close()
        Exit
EndFunc   ;==>Form1Close
 楼主| 发表于 2018-3-21 16:35:20 | 显示全部楼层
回复 18# zghwelcome

谢谢   谢谢  ,也感谢kk_lee69 和heroxianf 大侠的帮助,谢谢你们
发表于 2018-3-21 16:40:01 | 显示全部楼层
回复 18# zghwelcome


    fxk()
Quding()

为什么会同时放出来呢?
 楼主| 发表于 2018-3-21 16:42:42 | 显示全部楼层
回复 18# zghwelcome

是哈,为什么   fxk()
Quding()同时放出来呢?
发表于 2018-3-21 16:49:02 | 显示全部楼层
回复 20# heroxianf

这个问题得问楼主,我其实不知道要实现怎么样的效果,只是按照他的代码改了下,如果是要这样的,岂不是很简单,还搞什么自定义函数
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
$Form1 = GUICreate("Form1", 200, 178, -1, -1, BitOR($WS_SYSMENU, $WS_POPUP, $WS_SIZEBOX))
$Group1 = GUICtrlCreateGroup("", 5, 0, 189, 148)
$Checkbox1 = GUICtrlCreateCheckbox("全选", 16, 8, 97, 17)
$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)
$Button2 = GUICtrlCreateButton("退  出", 126, 150, 60, 23)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)

While 1
        Switch GUIGetMsg()
                Case $Button2
                        Exit

                Case $Checkbox1
                        If BitAND(GUICtrlRead($Checkbox1), $GUI_CHECKED) Then
                                For $i = 2 To 7 Step 1
                                        GUICtrlSetState(Eval('Checkbox' & $i), 1)
                                Next
                        Else
                                For $i = 2 To 7 Step 1
                                        GUICtrlSetState(Eval('Checkbox' & $i), 4)
                                Next
                        EndIf
                        
                Case $Button1
                        Local $text = ''
                        For $i = 2 To 7
                                If GUICtrlRead(Eval('Checkbox' & $i)) = 1 Then
                                        $text = $text & ControlGetText($Form1, '', Eval('Checkbox' & $i)) & ' '
                                EndIf
                        Next
                        $text = StringStripWS($text,3)
                        MsgBox(0,0,$text)
        EndSwitch
WEnd
发表于 2018-3-21 16:50:26 | 显示全部楼层
回复 21# qsy666888


    你好像是走弯路了,其实不用函数的吧
发表于 2018-3-21 16:53:15 | 显示全部楼层
回复 23# zghwelcome

主要是我和kk都认为他不是要用循环模式实现
 楼主| 发表于 2018-3-21 16:53:28 | 显示全部楼层
回复 23# zghwelcome
如果在一个窗口下,就简单了,在多窗口下,目前我只会用func,所以就出现这个问题了
发表于 2018-3-21 16:53:57 | 显示全部楼层
回复 12# qsy666888


    问题你写的是事件模式,另外你反复声明(34行)使原有的事件失效了。

#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Opt("GUIOnEventMode", 1) ;事件模式开启

fxk()

Func fxk()
        Global $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")
        GUISetOnEvent($GUI_EVENT_CLOSE, "Quding");退出
        GUICtrlCreateGroup("", -99, -99, 1, 1)
        GUISetState(@SW_SHOW)
        
EndFunc   ;==>fxk

While 1
        Sleep(100)
WEnd

Func Quding()
        Switch @GUI_CtrlId
                Case $Button2, $GUI_EVENT_CLOSE
                        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
发表于 2018-3-28 00:34:11 | 显示全部楼层
学习了,不错不错。
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-5-29 19:27 , Processed in 0.078291 second(s), 14 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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