GUI中OnEvent模式出现问题?【已解决】
本帖最后由 blue_dvd 于 2016-12-14 11:12 编辑按了“模块2”按钮后,“模块1”的按钮就弹不出菜单了,请高手指点,代码如下:
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ColorConstants.au3>
#include <GUIListView.au3>
#include <SQLite.au3>
#include <SQLite.dll.au3>
#include <MsgBoxConstants.au3>
#cs
系统主窗口
#ce
Opt("GUIOnEventMode", 1)
#Region ### START Koda GUI section ### Form=i:\autoit最新资料\tools\koda_1.7.3.0\forms\studentinfo2.kxf
$Form1_1 = GUICreate("测试系统", 1357, 717, 23, 76)
$ListView1 = GUICtrlCreateListView("", 16, 16, 569, 657)
$Group1 = GUICtrlCreateGroup("基本信息", 616, 32, 649, 321)
GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
$Label1 = GUICtrlCreateLabel("文本1:", 640, 64, 64, 28)
$Label2 = GUICtrlCreateLabel("文本2:", 800, 64, 104, 28)
$Label3 = GUICtrlCreateLabel("文本3:", 1048, 72, 64, 28)
$Label4 = GUICtrlCreateLabel("文本4:", 640, 120, 104, 28)
$Label5 = GUICtrlCreateLabel("文本5", 920, 120, 84, 28)
$Label6 = GUICtrlCreateLabel("文本6", 648, 160, 124, 28)
$Label7 = GUICtrlCreateLabel("文本7:", 648, 200, 144, 28)
$Label8 = GUICtrlCreateLabel("文本8:", 656, 240, 84, 28)
$Input1 = GUICtrlCreateInput("Input1", 704, 64, 57, 32)
$Input2 = GUICtrlCreateInput("Input2", 904, 64, 113, 32)
$Input3 = GUICtrlCreateInput("Input3", 1128, 64, 81, 32)
$Input4 = GUICtrlCreateInput("Input4", 752, 112, 121, 32)
$Input5 = GUICtrlCreateInput("Input5", 1032, 112, 145, 32)
$Input6 = GUICtrlCreateInput("Input6", 792, 152, 121, 32)
$Input7 = GUICtrlCreateInput("Input7", 840, 192, 73, 32)
$Input8 = GUICtrlCreateInput("Input8", 752, 232, 113, 32)
$Label9 = GUICtrlCreateLabel("备注", 672, 288, 44, 28)
$Input9 = GUICtrlCreateInput("Input9", 744, 280, 129, 32)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group2 = GUICtrlCreateGroup("功能区", 608, 416, 553, 225)
GUICtrlSetFont(-1, 18, 400, 0, "MS Sans Serif")
$Button1 = GUICtrlCreateButton("模块1", 656, 464, 153, 41)
$Button2 = GUICtrlCreateButton("模块2", 864, 464, 153, 41)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
GUISetOnEvent($GUI_EVENT_CLOSE, "_Main")
For $i=1 to6
;GUICtrlSetOnEvent(Eval("Button"&$i), "_Main")
GUICtrlSetOnEvent(Eval("Button"&String($i)), "_Main")
Next
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd
Func_Main()
Switch @GUI_CtrlId
Case $GUI_EVENT_CLOSE
Switch @GUI_WINHANDLE
Case $Form1_1
Exit
Case Else
GUIDelete(@GUI_WINHANDLE)
EndSwitch
Case $Button1
MsgBox(0,"提醒","模块1测试中")
GUISetOnEvent($GUI_EVENT_CLOSE,"_Main")
Case $Button2
_Every_month_Record()
; MsgBox(0,"提醒","模块2测试中")
GUISetOnEvent($GUI_EVENT_CLOSE,"_Main")
EndSwitch
EndFunc ;==>Main
Func _Every_month_Record()
$Form2 = GUICreate("每月结算登记", 753, 684, 427, 97)
$Label1 = GUICtrlCreateLabel("请选择结算房号:", 32, 24, 164, 28)
GUICtrlSetFont(-1, 15, 400, 0, "MS Sans Serif")
$Group1 = GUICtrlCreateGroup("房间基本信息", 24, 64, 681, 145)
GUICtrlSetFont(-1, 15, 400, 0, "MS Sans Serif")
$Label2 = GUICtrlCreateLabel("房号:", 40, 96, 64, 28)
$Input1 = GUICtrlCreateInput("Input1", 104, 96, 129, 32)
$Label3 = GUICtrlCreateLabel("入住时间:", 272, 96, 104, 28)
$Input2 = GUICtrlCreateInput("Input2", 384, 96, 209, 32)
$Label4 = GUICtrlCreateLabel("租客姓名:", 40, 144, 104, 28)
$Input3 = GUICtrlCreateInput("Input3", 152, 144, 145, 32)
$Label5 = GUICtrlCreateLabel("身份证:", 320, 144, 84, 28)
$Input4 = GUICtrlCreateInput("Input4", 416, 144, 225, 32)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group2 = GUICtrlCreateGroup("登记费用", 32, 248, 681, 177)
GUICtrlSetFont(-1, 15, 400, 0, "MS Sans Serif")
$Label6 = GUICtrlCreateLabel("电表月读数:", 48, 280, 124, 28)
$Input5 = GUICtrlCreateInput("Input5", 176, 280, 137, 32)
$Label7 = GUICtrlCreateLabel("水表月读数:", 48, 320, 124, 28)
$Input6 = GUICtrlCreateInput("Input6", 176, 320, 137, 32)
$Label8 = GUICtrlCreateLabel("网费:", 368, 280, 64, 28)
$Input7 = GUICtrlCreateInput("Input7", 456, 280, 105, 32)
$Label9 = GUICtrlCreateLabel("电视费:", 368, 328, 84, 28)
$Input8 = GUICtrlCreateInput("Input8", 456, 328, 113, 32)
$Label10 = GUICtrlCreateLabel("公用电费:", 48, 368, 104, 28)
$Input9 = GUICtrlCreateInput("Input9", 176, 368, 137, 32)
$Label11 = GUICtrlCreateLabel("其他:", 376, 368, 64, 28)
$Input10 = GUICtrlCreateInput("Input10", 456, 368, 105, 32)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group3 = GUICtrlCreateGroup("汇总小计", 32, 464, 681, 137)
GUICtrlSetFont(-1, 15, 400, 0, "MS Sans Serif")
$Label12 = GUICtrlCreateLabel("电费:", 48, 496, 64, 28)
$Label13 = GUICtrlCreateLabel("水费:", 368, 496, 64, 28)
$Input11 = GUICtrlCreateInput("Input11", 120, 496, 185, 32)
$Input12 = GUICtrlCreateInput("Input12", 448, 496, 177, 32)
$Label14 = GUICtrlCreateLabel("总计应收:", 56, 544, 104, 28)
$Input13 = GUICtrlCreateInput("Input13", 176, 544, 177, 32)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Button1 = GUICtrlCreateButton("登记完毕退出", 264, 616, 153, 41)
GUICtrlSetFont(-1, 15, 400, 0, "MS Sans Serif")
GUISetState(@SW_SHOW)
EndFunc
回复 1# blue_dvd
为什么不这样呢?
GUICtrlSetOnEvent($Button1, "_Button1")
GUICtrlSetOnEvent($Button2, "_Button2") 按了“模块2”按钮后,“模块1”的按钮就弹不出菜单了,请高手指点,代码如下:
blue_dvd 发表于 2016-12-11 10:18 http://www.autoitx.com/images/common/back.gif
这样试看看
For $i = 1 To 6
Local $sEvalString = Eval("Button" & $i)
GUICtrlSetOnEvent($sEvalString, "_Main")
Next
Func _Main()
;Switch ;@GUI_CtrlId
Select
Case @GUI_CtrlId = 25
;Case $Button2
MsgBox(0, "提醒", "模块1测试中")
;GUISetOnEvent($GUI_EVENT_CLOSE, "_Main")
Case @GUI_CtrlId = 26
;Case $Button1
_Every_month_Record()
; MsgBox(0,"提醒","模块2测试中")
;GUISetOnEvent($GUI_EVENT_CLOSE, "_Main")
EndSelect
;EndSwitch
EndFunc ;==>_Main 本帖最后由 q410225 于 2016-12-11 17:08 编辑
写的太乱了,我给你整理了一下,发现可以用了{:face (411):}
然后我又看了一下,原来一切都是$Button1 = GUICtrlCreateButton("登记完毕退出", 264, 616, 153, 41)的锅,
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ColorConstants.au3>
#include <GUIListView.au3>
#include <SQLite.au3>
#include <SQLite.dll.au3>
#include <MsgBoxConstants.au3>
#cs
系统主窗口
#ce
Opt("GUIOnEventMode", 1)
Local $Form1_1 = GUICreate("测试系统", 1357, 717, 23, 76)
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEButton")
Local $ListView1 = GUICtrlCreateListView("", 16, 16, 569, 657)
Local $Group1 = GUICtrlCreateGroup("基本信息", 616, 32, 649, 321)
GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
Local $Label1 = GUICtrlCreateLabel("文本1:", 640, 64, 64, 28)
Local $Label2 = GUICtrlCreateLabel("文本2:", 800, 64, 104, 28)
Local $Label3 = GUICtrlCreateLabel("文本3:", 1048, 72, 64, 28)
Local $Label4 = GUICtrlCreateLabel("文本4:", 640, 120, 104, 28)
Local $Label5 = GUICtrlCreateLabel("文本5", 920, 120, 84, 28)
Local $Label6 = GUICtrlCreateLabel("文本6", 648, 160, 124, 28)
Local $Label7 = GUICtrlCreateLabel("文本7:", 648, 200, 144, 28)
Local $Label8 = GUICtrlCreateLabel("文本8:", 656, 240, 84, 28)
Local $Input1 = GUICtrlCreateInput("Input1", 704, 64, 57, 32)
Local $Input2 = GUICtrlCreateInput("Input2", 904, 64, 113, 32)
Local $Input3 = GUICtrlCreateInput("Input3", 1128, 64, 81, 32)
Local $Input4 = GUICtrlCreateInput("Input4", 752, 112, 121, 32)
Local $Input5 = GUICtrlCreateInput("Input5", 1032, 112, 145, 32)
Local $Input6 = GUICtrlCreateInput("Input6", 792, 152, 121, 32)
Local $Input7 = GUICtrlCreateInput("Input7", 840, 192, 73, 32)
Local $Input8 = GUICtrlCreateInput("Input8", 752, 232, 113, 32)
Local $Label9 = GUICtrlCreateLabel("备注", 672, 288, 44, 28)
Local $Input9 = GUICtrlCreateInput("Input9", 744, 280, 129, 32)
GUICtrlCreateGroup("", -99, -99, 1, 1)
Local $Group2 = GUICtrlCreateGroup("功能区", 608, 416, 553, 225)
GUICtrlSetFont(-1, 18, 400, 0, "MS Sans Serif")
Local $Button1 = GUICtrlCreateButton("模块1", 656, 464, 153, 41)
GUICtrlSetOnEvent($Button1, "button1")
Local $Button2 = GUICtrlCreateButton("模块2", 864, 464, 153, 41)
GUICtrlSetOnEvent($Button2, "button2")
GUICtrlCreateGroup("", -99, -99, 1, 1)
Local $Form2 = GUICreate("每月结算登记", 753, 684, 427, 97)
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEButton")
Local $Label1 = GUICtrlCreateLabel("请选择结算房号:", 32, 24, 164, 28)
GUICtrlSetFont(-1, 15, 400, 0, "MS Sans Serif")
Local $Group1 = GUICtrlCreateGroup("房间基本信息", 24, 64, 681, 145)
GUICtrlSetFont(-1, 15, 400, 0, "MS Sans Serif")
Local $Label2 = GUICtrlCreateLabel("房号:", 40, 96, 64, 28)
Local $Input1 = GUICtrlCreateInput("Input1", 104, 96, 129, 32)
Local $Label3 = GUICtrlCreateLabel("入住时间:", 272, 96, 104, 28)
Local $Input2 = GUICtrlCreateInput("Input2", 384, 96, 209, 32)
Local $Label4 = GUICtrlCreateLabel("租客姓名:", 40, 144, 104, 28)
Local $Input3 = GUICtrlCreateInput("Input3", 152, 144, 145, 32)
Local $Label5 = GUICtrlCreateLabel("身份证:", 320, 144, 84, 28)
Local $Input4 = GUICtrlCreateInput("Input4", 416, 144, 225, 32)
GUICtrlCreateGroup("", -99, -99, 1, 1)
Local $Group2 = GUICtrlCreateGroup("登记费用", 32, 248, 681, 177)
GUICtrlSetFont(-1, 15, 400, 0, "MS Sans Serif")
Local $Label6 = GUICtrlCreateLabel("电表月读数:", 48, 280, 124, 28)
Local $Input5 = GUICtrlCreateInput("Input5", 176, 280, 137, 32)
Local $Label7 = GUICtrlCreateLabel("水表月读数:", 48, 320, 124, 28)
Local $Input6 = GUICtrlCreateInput("Input6", 176, 320, 137, 32)
Local $Label8 = GUICtrlCreateLabel("网费:", 368, 280, 64, 28)
Local $Input7 = GUICtrlCreateInput("Input7", 456, 280, 105, 32)
Local $Label9 = GUICtrlCreateLabel("电视费:", 368, 328, 84, 28)
Local $Input8 = GUICtrlCreateInput("Input8", 456, 328, 113, 32)
Local $Label10 = GUICtrlCreateLabel("公用电费:", 48, 368, 104, 28)
Local $Input9 = GUICtrlCreateInput("Input9", 176, 368, 137, 32)
Local $Label11 = GUICtrlCreateLabel("其他:", 376, 368, 64, 28)
Local $Input10 = GUICtrlCreateInput("Input10", 456, 368, 105, 32)
GUICtrlCreateGroup("", -99, -99, 1, 1)
Local $Group3 = GUICtrlCreateGroup("汇总小计", 32, 464, 681, 137)
GUICtrlSetFont(-1, 15, 400, 0, "MS Sans Serif")
Local $Label12 = GUICtrlCreateLabel("电费:", 48, 496, 64, 28)
Local $Label13 = GUICtrlCreateLabel("水费:", 368, 496, 64, 28)
Local $Input11 = GUICtrlCreateInput("Input11", 120, 496, 185, 32)
Local $Input12 = GUICtrlCreateInput("Input12", 448, 496, 177, 32)
Local $Label14 = GUICtrlCreateLabel("总计应收:", 56, 544, 104, 28)
Local $Input13 = GUICtrlCreateInput("Input13", 176, 544, 177, 32)
GUICtrlCreateGroup("", -99, -99, 1, 1)
Local $Button1 = GUICtrlCreateButton("登记完毕退出", 264, 616, 153, 41)
GUICtrlSetOnEvent($Button1, "Button1")
GUICtrlSetFont(-1, 15, 400, 0, "MS Sans Serif")
GUISetState(@SW_SHOW,$Form1_1)
While 1
Sleep(100)
WEnd
Func CLOSEButton()
If @GUI_WinHandle = $Form1_1 Then
Exit
Else
GUISetState(@SW_HIDE)
;GUISetState(@SW_SHOW, $Form1_1)
EndIf
EndFunc ;==>CLOSEButton
Func button1()
If @GUI_WinHandle = $Form1_1 Then
MsgBox(0, "", "太乱啦,什么都干不成!")
Else
GUISetState(@SW_HIDE)
;GUISetState(@SW_SHOW, $Form1_1)
EndIf
EndFunc ;==>button1
Func button2()
GUISetState(@SW_SHOW, $Form2)
EndFunc ;==>button2
无论如何,都得大改,因为FORM2是无效的,{:face (361):} 回复 5# q410225
为什么FORM2这样会无效? 回复 6# blue_dvd
我是这样理解的
事件模式下,你需要给每个窗体里的控件单独设置触发条件,比如那个关闭事件,在form1里,有这么一句话GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEButton")到了form2里,也有。GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEButton")还有button1,也要同时在两个窗体都设置了触发条件。
而你只是定义了FORM1的触发条件,FORM2没有,所以,我觉得FORM2应该是无效的。 回复q410225
为什么FORM2这样会无效?
blue_dvd 发表于 2016-12-11 18:52 http://www.autoitx.com/images/common/back.gif
你手好象有点懒------
按你的代码修改缩短了一下,你看看这样行不?
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ColorConstants.au3>
#include <GUIListView.au3>
#include <SQLite.au3>
#include <SQLite.dll.au3>
#include <MsgBoxConstants.au3>
#cs
系统主窗口
#ce
Opt("GUIOnEventMode", 1)
Global $Form2
#Region ### START Koda GUI section ### Form=i:\autoit最新资料\tools\koda_1.7.3.0\forms\studentinfo2.kxf
$Form1_1 = GUICreate("测试系统", 800, 600, -1, -1)
$Button1 = GUICtrlCreateButton("模块1", 10, 464, 80, 41)
$Button2 = GUICtrlCreateButton("模块2", 110, 464, 80, 41)
$Button3 = GUICtrlCreateButton("模块3", 210, 464, 80, 41)
$Button4 = GUICtrlCreateButton("模块4", 310, 464, 80, 41)
$Button5 = GUICtrlCreateButton("模块5", 410, 464, 80, 41)
$Button6 = GUICtrlCreateButton("模块6", 510, 464, 80, 41)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
GUISetOnEvent($GUI_EVENT_CLOSE, "_Maina")
For $i = 1 To 6
Local $sEvalString = Eval("Button" & $i)
GUICtrlSetOnEvent($sEvalString, "_Main")
Next
While 1
Sleep(1000)
WEnd
Func _Main()
Select
Case @GUI_CtrlId = 3
MsgBox(0, "提醒", "模块1测试中")
Case @GUI_CtrlId = 4
_Every_month_Record()
Case @GUI_CtrlId = 5
MsgBox(0, "提醒", "模块3测试中")
Case @GUI_CtrlId = 6
MsgBox(0, "提醒", "模块4测试中")
Case @GUI_CtrlId = 7
MsgBox(0, "提醒", "模块5测试中")
Case @GUI_CtrlId = 8
MsgBox(0, "提醒", "模块6测试中")
EndSelect
EndFunc ;==>_Main
Func _Maina()
Switch @GUI_CtrlId
Case $GUI_EVENT_CLOSE
Switch @GUI_WinHandle
Case $Form1_1
Exit
Case Else
GUIDelete(@GUI_WinHandle)
EndSwitch
EndSwitch
EndFunc ;==>_Maina
Func _Every_month_Record()
$Form2 = GUICreate("每月结算登记", 653, 444, -1, 126)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Form2Close")
$Label1 = GUICtrlCreateLabel("请选择结算房号:", 32, 24, 164, 28)
GUICtrlSetFont(-1, 15, 400, 0, "MS Sans Serif")
$Group1 = GUICtrlCreateGroup("房间基本信息", 24, 64, 681, 145)
GUICtrlSetFont(-1, 15, 400, 0, "MS Sans Serif")
$Label2 = GUICtrlCreateLabel("房号:", 40, 96, 64, 28)
$Input1 = GUICtrlCreateInput("Input1", 104, 96, 129, 32)
$Label3 = GUICtrlCreateLabel("入住时间:", 272, 96, 104, 28)
$Input2 = GUICtrlCreateInput("Input2", 384, 96, 209, 32)
$Label4 = GUICtrlCreateLabel("租客姓名:", 40, 144, 104, 28)
$Input3 = GUICtrlCreateInput("Input3", 152, 144, 145, 32)
$Label5 = GUICtrlCreateLabel("身份证:", 320, 144, 84, 28)
$Input4 = GUICtrlCreateInput("Input4", 416, 144, 225, 32)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Button1 = GUICtrlCreateButton("登记完毕退出", 264, 226, 153, 41)
GUICtrlSetFont(-1, 15, 400, 0, "MS Sans Serif")
GUICtrlSetOnEvent($Button1, "_Button1")
GUISetState(@SW_SHOW, $Form2)
EndFunc ;==>_Every_month_Record
Func _Form2Close()
GUISetState(@SW_HIDE, $Form2)
EndFunc ;==>_Form2Close
Func _Button1()
MsgBox(0, "提醒", "登记完毕退出")
EndFunc ;==>_Button1
回复 8# chzj589
{:face (396):}
不错,你这个应该是最符合楼主要求的, 回复 8# chzj589
首先太感谢了,困扰了一个星期的问题可以解决了,但有个疑问:
@GUI_CtrlId = 3
@GUI_CtrlId = 4
那个值是固定的吗?怎么来的? 回复 4# q410225
是的,我也觉得是
$Button1 = GUICtrlCreateButton("登记完毕退出", 264, 616, 153, 41)
有问题,但是就是不知道原因? 回复chzj589
首先太感谢了,困扰了一个星期的问题可以解决了,但有个疑问:那个值是固定的吗?怎么来的 ...
blue_dvd 发表于 2016-12-11 23:54 http://www.autoitx.com/images/common/back.gif
值不是固定的,它是窗口控件的ID,随着窗口控件的排列而改变。
For $i = 1 To 6
Local $sEvalString = Eval("Button" & $i)
MsgBox(0, "提醒", $sEvalString)
GUICtrlSetOnEvent($sEvalString, "_Main")
Next
添加 MsgBox(0, "提醒", $sEvalString) 就清楚是怎么来的。
去掉上面的代码,换下面的代码会好一些,这样就是固定的
GUICtrlSetOnEvent($Button1, "_Main")
GUICtrlSetOnEvent($Button2, "_Main")
GUICtrlSetOnEvent($Button3, "_Main")
GUICtrlSetOnEvent($Button4, "_Main")
GUICtrlSetOnEvent($Button5, "_Main")
GUICtrlSetOnEvent($Button6, "_Main") 回复 7# q410225
在FORM2哪里再设置触发条件就行呢? 回复q410225
在FORM2哪里再设置触发条件就行呢?
blue_dvd 发表于 2016-12-12 09:03 http://www.autoitx.com/images/common/back.gif
有关系吗?
;GUICtrlSetOnEvent($Button1, "_Button1")
把FORM2里的设置触发都注释掉也可运行
GUISetOnEvent($GUI_EVENT_CLOSE, "_Form2Close")
这一句如果注释掉,FORM2窗口不能关闭,但也可以运行 尽可能少用eval,可以考虑使用数组。
页:
[1]
2