找回密码
 加入
搜索
查看: 3544|回复: 11

请问有什么办法可以让GUICtrlCreateInput只能输入数字和字母。

[复制链接]
发表于 2009-3-21 01:43:53 | 显示全部楼层 |阅读模式
请问有什么办法可以让GUICtrlCreateInput只能输入数字和字母
#include <GUIConstantsEx.au3>

Opt('MustDeclareVars', 1)

Example()

Func Example()
        Local $file, $btn, $msg
       
        GUICreate(" My GUI input acceptfile", 320, 120, @DesktopWidth / 2 - 160, @DesktopHeight / 2 - 45, -1, 0x00000018); WS_EX_ACCEPTFILES
        $file = GUICtrlCreateInput("", 10, 5, 300, 20)
        GUICtrlSetState(-1, $GUI_DROPACCEPTED)
        GUICtrlCreateInput("", 10, 35, 300, 20)         ; will not accept drag&drop files
        $btn = GUICtrlCreateButton("Ok", 40, 75, 60, 20)

        GUISetState()

        $msg = 0
        While $msg <> $GUI_EVENT_CLOSE
                $msg = GUIGetMsg()
                Select
                        Case $msg = $btn
                                ExitLoop
                EndSelect
        WEnd

        MsgBox(4096, "drag drop file", GUICtrlRead($file))
EndFunc   ;==>Example

[ 本帖最后由 ddx13 于 2009-3-21 13:00 编辑 ]
发表于 2009-3-21 02:30:08 | 显示全部楼层
不懂,学习...
帮你顶上....
发表于 2009-3-21 03:10:23 | 显示全部楼层

看看能不能用


#include <GUIConstantsEx.au3>


$Form = GUICreate("Form1", 633, 454, 192, 114)
$Inputuser = GUICtrlCreateInput("", 82, 90, 93, 20)
$Label = GUICtrlCreateLabel("", 186, 91, 160, 20)
$Inputpass = GUICtrlCreateInput("", 82, 120, 93, 20)
$ccccc = GUICtrlCreateButton("Check", 100, 150, 75, 25)
GUISetState(@SW_SHOW)

While 1
        $msg = GUIGetMsg()
        Select
                Case $msg = $GUI_EVENT_CLOSE
                        Exit
                Case $msg = $Inputuser
                        InputCheck()
        EndSelect
WEnd


Func InputCheck()
        $user = GUICtrlRead($Inputuser)
        If Not StringRegExp($user, "^[A-Za-z0-9]+$") Then
                GUICtrlSetState($Inputuser, $GUI_FOCUS)
                GUICtrlSetData($Label, "X 只允许输入英文字母和数字.")
                GUICtrlSetColor($Label, 0xFF0000)
                GUICtrlSetFont($Label, 9, 400, 0, "Tahoma")
        Else
                GUICtrlSetData($Label, "√ 输入正确.")
                GUICtrlSetFont($Label, 9, 800, 0, "Tahoma")
                GUICtrlSetColor($Label, 0x008000)
                GUICtrlSetFont($Label, 9, 400, 0, "Tahoma")
        EndIf
EndFunc   ;==>InputCheck
 楼主| 发表于 2009-3-21 08:40:14 | 显示全部楼层
谢谢,你这样只是有提示,而我希望的是,在Input中只能输入数字和母字,就有点象加入了$ES_NUMBER的样子。
发表于 2009-3-21 09:09:07 | 显示全部楼层
使用正则表达式吧,3楼的例子已经完全满足把你的要求

[ 本帖最后由 fanchenglu 于 2009-3-21 09:14 编辑 ]
发表于 2009-3-21 09:32:45 | 显示全部楼层
[au3]#include <GUIConstants.au3>

#Region ### START Koda GUI section ### Fandm=
$Form1 = GUICreate("Form1", 431, 204, 193, 115)
$Input1 = GUICtrlCreateInput("Input1", 176, 72, 121, 21)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
        $text=Asc(StringRight(GUICtrlRead($Input1),1))
        if _IsFocused($Form1,$Input1) and ($text<48 or $text>57) and  ($text<65 Or $text>90) and ($text<97 or $text>122) Then GUICtrlSetData($Input1,StringLeft(GUICtrlRead($Input1),StringLen(GUICtrlRead($Input1))-1))
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit

        EndSwitch
WEnd

Func _IsFocused($hWnd, $nCID)
    Return ControlGetHandle($hWnd, '', $nCID) = ControlGetHandle($hWnd, '', ControlGetFocus($hWnd))
EndFunc[/au3]
发表于 2009-3-21 11:47:01 | 显示全部楼层
呵呵,灰狼代码还得改进一下,因为我可以复制中文文本进去的
 楼主| 发表于 2009-3-21 13:00:02 | 显示全部楼层
其实方法我到是有,本以为有什么函数可以实现的。
下面是我自己写的一段代码,给大家供参考。

#include <GUIConstants.au3>
Dim $QZZF
#Region ### START Koda GUI section ### Fandm=
$Form1 = GUICreate("Form1", 431, 204, 193, 115)
$Input1 = GUICtrlCreateInput("Input1", 176, 72, 121, 21)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
        $INPUTZA=GUICtrlRead($Input1)
        If $INPUTZA <> $QZZF Then
                if StringIsUpper ( StringRegExpReplace(StringStripWS ( StringUpper ( $INPUTZA ),8),"[1234567890]","A"))=1 then
                        $QZZF = $INPUTZA
                else
                        GUICtrlSetData($Input1, $QZZF)
                endif
        EndIf
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit

        EndSwitch
WEnd

[ 本帖最后由 ddx13 于 2009-3-22 00:45 编辑 ]
发表于 2009-3-21 22:20:54 | 显示全部楼层
你做的才经典呢,我直接可以输入中文
发表于 2013-5-11 09:47:33 | 显示全部楼层
大绯狼的代码写的太好了可以借鉴一下
发表于 2014-1-29 14:27:59 | 显示全部楼层
正好用的,借鉴一下,感谢。
发表于 2014-1-29 15:19:00 | 显示全部楼层
学习了,收藏备用
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-6-3 04:17 , Processed in 0.079231 second(s), 19 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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