找回密码
 加入
搜索
查看: 1900|回复: 8

Gui---添加事件不能响应???

[复制链接]
发表于 2009-3-3 15:20:26 | 显示全部楼层 |阅读模式
当选择相应单选按钮,点击“自动连接”时
就执行相应的命令,这些命令要如何添加
第一次用GUI工具的,请前辈们指点一下。
谢谢!!!!!!!
我加的代码(4楼的)不能响应,是代码错了吗??
用自带的界面工具设计好了,如下图:


[ 本帖最后由 zjg2003 于 2009-3-5 23:08 编辑 ]

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
 楼主| 发表于 2009-3-3 15:22:28 | 显示全部楼层
这是自动生成的代码:

#include <GUIConstants.au3>

#Region ### START Koda GUI section ### Form=c:\documents and settings\administrator\桌面\au3--serv--gui\服务器自动连接工具.kxf
$AForm1_1 = GUICreate("服务器自动连接工具", 313, 168, 291, 171)
$Radio1 = GUICtrlCreateRadio("网维游戏服务器", 20, 16, 113, 17)
GUICtrlSetState(-1, $GUI_CHECKED)
$Radio2 = GUICtrlCreateRadio("飞鱼星路由器", 21, 42, 113, 17)
$Radio3 = GUICtrlCreateRadio("网管专用计算机", 172, 16, 113, 17)
$Radio4 = GUICtrlCreateRadio("登陆Ftp 服务器", 173, 41, 113, 17)
$Label1 = GUICtrlCreateLabel("请先选择项目,然后在下面输入相应的帐号和密码", 21, 66, 268, 17)
$Label2 = GUICtrlCreateLabel("用户名:", 21, 95, 52, 17)
$Label3 = GUICtrlCreateLabel("密码:", 163, 95, 40, 17)
$Input1 = GUICtrlCreateInput("", 67, 93, 89, 21)
$Input2 = GUICtrlCreateInput("", 203, 92, 81, 21)
$Button1 = GUICtrlCreateButton("自动登陆", 38, 125, 81, 22, 0)
$Button2 = GUICtrlCreateButton("退出程序", 182, 126, 81, 22, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit

        EndSwitch
WEnd
发表于 2009-3-3 15:27:31 | 显示全部楼层
说下思路:
1. 点击自动登陆后,首先判断哪个单选框被选中,并获取用户名与密码文本框中的内容;
2. 在自动登陆按钮的响应事件里添加针对各个单选框被选后的连接代码。

注: GUICtrlSetOnEvent($okbutton, "OKButton")就是将$okbutton按钮的相应事件函数设定为OKButton函数。
例子:
#include <GUIConstantsEx.au3>

Opt("GUIOnEventMode", 1)  ; Change to OnEvent mode 
$mainwindow = GUICreate("Hello World", 200, 100)
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")
GUICtrlCreateLabel("Hello world! How are you?", 30, 10)
$okbutton = GUICtrlCreateButton("OK", 70, 50, 60)
GUICtrlSetOnEvent($okbutton, "OKButton")
GUISetState(@SW_SHOW)

While 1
  Sleep(1000)  ; Idle around
WEnd

Func OKButton()
  ;Note: at this point @GUI_CTRLID would equal $okbutton,
  ;and @GUI_WINHANDLE would equal $mainwindow
  MsgBox(0, "GUI Event", "You pressed OK!")
EndFunc

Func CLOSEClicked()
  ;Note: at this point @GUI_CTRLID would equal $GUI_EVENT_CLOSE, 
  ;and @GUI_WINHANDLE would equal $mainwindow 
  MsgBox(0, "GUI Event", "You clicked CLOSE! Exiting...")
  Exit
EndFunc


[ 本帖最后由 firewzy 于 2009-3-3 15:28 编辑 ]
发表于 2009-3-4 01:45:36 | 显示全部楼层
koda选 生成基于OnEvent的代码
 楼主| 发表于 2009-3-5 09:46:56 | 显示全部楼层
首先要谢谢两位的帮助,但我改成这样却不能响应事件,哪出错了吗???

#include <GUIConstants.au3>

#Region ### START Koda GUI section ### Form=c:\documents and settings\administrator\桌面\au3--serv--gui\服务器自动连接工具.kxf
$AForm1 = GUICreate("服务器自动连接工具", 313, 168, 291, 171)
$Radio1 = GUICtrlCreateRadio("网维游戏服务器", 20, 16, 113, 17)
GUICtrlSetState(-1, $GUI_CHECKED)
$Radio2 = GUICtrlCreateRadio("飞鱼星路由器", 21, 42, 113, 17)
$Radio3 = GUICtrlCreateRadio("网管专用计算机", 172, 16, 113, 17)
$Radio4 = GUICtrlCreateRadio("登陆Ftp 服务器", 173, 41, 113, 17)
$Label1 = GUICtrlCreateLabel("请先选择项目,然后在下面输入相应的帐号和密码", 21, 66, 268, 17)
$Label2 = GUICtrlCreateLabel("用户名:", 21, 95, 52, 17)
$Label3 = GUICtrlCreateLabel("密码:", 163, 95, 40, 17)
$Input1 = GUICtrlCreateInput("", 67, 93, 89, 21)
$Input2 = GUICtrlCreateInput("", 203, 92, 81, 21)
$Button1 = GUICtrlCreateButton("自动登陆", 38, 125, 81, 22, 0)
GUISetOnEvent(-1,"okbit")
$Button2 = GUICtrlCreateButton("退出程序", 182, 126, 81, 22, 0)
GUISetOnEvent(-1,"exitbit")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit

        EndSwitch
WEnd

Func okbit()
        Select
                Case GUICtrlSetState($Radio1, $GUI_CHECKED)
                        MsgBox(0, "控件选择", "你选择的是网维" )
                Case GUICtrlSetState($Radio2, $GUI_CHECKED)
                        MsgBox(0, "控件选择", "你选择的是路由" )
                Case GUICtrlSetState($Radio3, $GUI_CHECKED)
                        MsgBox(0, "控件选择", "你选择的是网管" )       
                Case GUICtrlSetState($Radio4, $GUI_CHECKED)
                        MsgBox(0, "控件选择", "你选择的是FTP" )       
        EndSelect               
EndFunc       
Func exitbit()
        Exit
EndFunc

[ 本帖最后由 zjg2003 于 2009-3-5 10:58 编辑 ]
发表于 2009-3-5 12:50:02 | 显示全部楼层
为什么新手就不能先看一看帮助!

Opt('GUIOnEventMode', 1)
#Region ### START Koda GUI section ### Form=
$AForm1 = GUICreate("服务器自动连接工具", 313, 168, 291, 171)
$Radio1 = GUICtrlCreateRadio("网维游戏服务器", 20, 16, 113, 17)
GUICtrlSetState(-1, 1)
$Radio2 = GUICtrlCreateRadio("飞鱼星路由器", 21, 42, 113, 17)
$Radio3 = GUICtrlCreateRadio("网管专用计算机", 172, 16, 113, 17)
$Radio4 = GUICtrlCreateRadio("登陆Ftp 服务器", 173, 41, 113, 17)
$Label1 = GUICtrlCreateLabel("请先选择项目,然后在下面输入相应的帐号和密码", 21, 66, 268, 17)
$Label2 = GUICtrlCreateLabel("用户名:", 21, 95, 52, 17)
$Label3 = GUICtrlCreateLabel("密码:", 163, 95, 40, 17)
$Input1 = GUICtrlCreateInput("", 67, 93, 89, 21)
$Input2 = GUICtrlCreateInput("", 203, 92, 81, 21)
$Button1 = GUICtrlCreateButton("自动登陆", 38, 125, 81, 22, 0)
GUICtrlSetOnEvent(-1, "okbit")
$Button2 = GUICtrlCreateButton("退出程序", 182, 126, 81, 22, 0)
GUICtrlSetOnEvent(-1, "exitbit")
GUISetOnEvent(-3, "exitbit")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
        Sleep(90)
WEnd

Func okbit()
        Select
                Case GUICtrlRead($Radio1) = 1
                        MsgBox(0, "控件选择", "你选择的是网维")
                Case GUICtrlRead($Radio2) = 1
                        MsgBox(0, "控件选择", "你选择的是路由")
                Case GUICtrlRead($Radio3) = 1
                        MsgBox(0, "控件选择", "你选择的是网管")
                Case GUICtrlRead($Radio4) = 1
                        MsgBox(0, "控件选择", "你选择的是FTP")
        EndSelect
EndFunc   ;==>okbit

Func exitbit()
        Exit
EndFunc   ;==>exitbit
发表于 2009-3-5 19:40:28 | 显示全部楼层
应该先理解概念

请先看帮助的 gui解释那3页 而不要从GUICreate开始
 楼主| 发表于 2009-3-5 23:07:46 | 显示全部楼层
谢谢楼上两位
发表于 2009-3-6 02:44:20 | 显示全部楼层
#include <GUIConstantsEx.au3>
Opt('GUIOnEventMode', 1)
#Region ### START Koda GUI section ### Form=
$AForm1 = GUICreate("服务器自动连接工具", 313, 168, 291, 171)
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")
$Radio1 = GUICtrlCreateRadio("网维游戏服务器", 20, 16, 113, 17)
$Radio2 = GUICtrlCreateRadio("飞鱼星路由器", 21, 42, 113, 17)
$Radio3 = GUICtrlCreateRadio("网管专用计算机", 172, 16, 113, 17)
$Radio4 = GUICtrlCreateRadio("登陆Ftp 服务器", 173, 41, 113, 17)
$Label1 = GUICtrlCreateLabel("请先选择项目,然后在下面输入相应的帐号和密码", 21, 66, 268, 17)
$Label2 = GUICtrlCreateLabel("用户名:", 21, 95, 52, 17)
$Label3 = GUICtrlCreateLabel("密码:", 163, 95, 40, 17)
$Input1 = GUICtrlCreateInput("", 67, 93, 89, 21)
$Input2 = GUICtrlCreateInput("", 203, 92, 81, 21)
$Button1 = GUICtrlCreateButton("自动登陆", 38, 125, 81, 22, 0)
$Button2 = GUICtrlCreateButton("退出程序", 182, 126, 81, 22, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
GUICtrlSetOnEvent($Radio1 , "Radio1")
While 1
  Sleep(1000)  ; Idle around
WEnd

Func Radio1()
                        MsgBox(0, "控件选择", "你选择的是网维")
EndFunc   ;==>okbit

Func CLOSEClicked()

  MsgBox(0, "GUI Event", "You clicked CLOSE! Exiting...")
  Exit
EndFunc

[ 本帖最后由 116154801 于 2009-3-6 02:46 编辑 ]
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-5-18 22:38 , Processed in 0.088116 second(s), 21 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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