找回密码
 加入
搜索
查看: 1576|回复: 5

如何设置缺省按钮?

[复制链接]
发表于 2009-3-8 12:32:54 | 显示全部楼层 |阅读模式
1。高手帮忙看如何设置下面代码中的  $Button1   为缺省按钮,就是我们直接回车就相当于点击了按钮
2。还有就是帮忙看下面代码中的 IF  这段,想要设置为当用户名或密码为空时弹出提示后,不要退出程序,并且不执行后面的代码。

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()
        If GUICtrlRead($Input1)="" or GUICtrlRead($Input2)="" Then
                MsgBox(0, "提示", "请先输入正确的用户名和密码!")       
                Exit
        EndIf

    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

[ 本帖最后由 zjg2003 于 2009-3-8 18:44 编辑 ]
发表于 2009-3-8 12:41:01 | 显示全部楼层
1.GUICtrlSetState ($Button1 , $GUI_FOCUS ) 设置得到控件得到焦点

2.Func okbit()
        If GUICtrlRead($Input1)="" or GUICtrlRead($Input2)="" Then
                MsgBox(0, "提示", "请先输入正确的用户名和密码!")        
        Else
    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
   EndIf
EndFunc   ;==>okbit

先看看帮助文档再提问行吗?

[ 本帖最后由 xrbenbeba 于 2009-3-8 12:42 编辑 ]
发表于 2009-3-8 16:56:53 | 显示全部楼层
GUICtrlSetState($Button1, $GUI_DEFBUTTON)
发表于 2009-3-8 17:02:38 | 显示全部楼层
记得加上
#include <GUIConstantsEx.au3>
或直接设置 GUICtrlSetState($Button1, 512)
 楼主| 发表于 2009-3-8 18:44:13 | 显示全部楼层
谢谢两位

努力学习中^^^
发表于 2009-3-8 18:49:03 | 显示全部楼层
原帖由 zjg2003 于 2009-3-8 18:44 发表
谢谢两位

努力学习中^^^


多看帮助文档就行了  很简单的问题
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-5-19 01:24 , Processed in 0.070956 second(s), 20 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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