如何让事件模式下的不同控件的事件连续触发?
在事件模式下,比如有三个控件:文本框,按钮1,按钮2。按钮2初始是禁用的。文本框的事件:当文本框中有输入文本后,按钮2被激活。
按钮1的事件:向文本框内设置文本。
希望的效果是按钮1的事件触发后由于文本框满足条件会触发文本框的事件,想要这样的效果只能再在按钮1的事件方法中加入激活按钮2的动作。这样感觉代码很冗余,有没有什么别的方法不在按钮1的事件中添加激活按钮2的动作就能够让这两个事件连续触发,类似于多米诺那样。 本帖最后由 fangbaiyu 于 2013-8-9 22:50 编辑
鄙人语文很差 看了LZ的问题 很凌乱
乱写了一通LZ看看 是不是你想要的效果
例一:#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <SendMessage.au3>
Opt("GUIOnEventMode", 1)
Opt("MustDeclareVars", 1)
Global $gu_hMainForm = GUICreate("", 200, 300)
Global $gu_nEdit = GUICtrlCreateEdit("", 10, 10, 180, 220)
Global $gu_nButton1 = GUICtrlCreateButton("Button1", 30, 250, 50, 30)
Global $gu_nButton2 = GUICtrlCreateButton("Button2", 110, 250, 50, 30)
Global $gu_hEdit = GUICtrlGetHandle($gu_nEdit)
GUICtrlSetOnEvent($gu_nButton1, "_MY_EVENT")
GUICtrlSetOnEvent($gu_nEdit, "_MY_EVENT")
GUISetOnEvent($GUI_EVENT_CLOSE, "_MY_EVENT")
GUICtrlSetState($gu_nButton2, $GUI_DISABLE)
GUISetState(@SW_SHOW)
While 1
Sleep(10)
WEnd
GUIDelete()
Exit
Func _MY_EVENT()
Local $t_bVar
Switch @GUI_CtrlId
Case $GUI_EVENT_CLOSE
Exit
Case $gu_nButton1
$t_bVar = GUICtrlSetData($gu_nEdit, "Test", 1)
If $t_bVar Then _SendMessage($gu_hMainForm, $WM_COMMAND, $EN_CHANGE, 0)
Case $gu_nEdit
GUICtrlSetState($gu_nButton2, $GUI_ENABLE)
EndSwitch
EndFunc例二:#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <SendMessage.au3>
Opt("GUIOnEventMode", 1)
Opt("MustDeclareVars", 1)
Global $gu_hMainForm = GUICreate("", 200, 300)
Global $gu_nEdit = GUICtrlCreateEdit("", 10, 10, 180, 220)
Global $gu_nButton1 = GUICtrlCreateButton("Button1", 30, 250, 50, 30)
Global $gu_nButton2 = GUICtrlCreateButton("Button2", 110, 250, 50, 30)
Global $gu_hEdit = GUICtrlGetHandle($gu_nEdit)
GUICtrlSetOnEvent($gu_nButton1, "_MY_EVENT")
GUICtrlSetOnEvent($gu_nEdit, "_MY_EVENT")
GUISetOnEvent($GUI_EVENT_CLOSE, "_MY_EVENT")
GUICtrlSetState($gu_nButton2, $GUI_DISABLE)
GUISetState(@SW_SHOW)
GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND")
While 1
Sleep(10)
WEnd
GUIDelete()
Exit
Func _WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)
Local $wNotifyCode = BitShift($wParam, 16)
Local $wID = BitAND($wParam, 0x0000FFFF)
Local $hWndCtrl = $lParam
Switch $hWndCtrl
Case $gu_hEdit
Switch $wNotifyCode
Case $EN_UPDATE
GUICtrlSetState($gu_nButton2, $GUI_ENABLE)
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc
Func _MY_EVENT()
Switch @GUI_CtrlId
Case $GUI_EVENT_CLOSE
Exit
Case $gu_nButton1
GUICtrlSetData($gu_nEdit, "Test", 1)
EndSwitch
EndFunc
页:
[1]