以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  只能输入汉字  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=147335)

--  作者:良才
--  发布时间:2020/3/14 14:26:00
--  只能输入汉字
DropDownBox1只能输入汉字

KeyPress代码

If PY.IsHanzi(e.KeyChar) Then
Else
    e.Cancel  = True
End If
删除键(Backspace)无用了,请老师指教,谢谢!

--  作者:有点蓝
--  发布时间:2020/3/14 15:00:00
--  
If PY.IsHanzi(e.KeyChar) orelse e.keycode = keys.Back Then
[此贴子已经被作者于2020/3/14 15:00:44编辑过]

--  作者:程兴刚
--  发布时间:2020/3/14 15:21:00
--  
参考这个,我原来在 PY.IsHanzi还没有的时候用的正则表达式方案

Dim City As String = e.Sender.text
If City > ""
    Dim reg = new System.Text.RegularExpressions.Regex("^[\\u4e00-\\u9fa5]{0,}$")
    If reg.Ismatch(City) = False Then
        Sendkeys.SendWait("{Backspace}")
        MessageBox.show("对不起,城市名必须是正确的汉字名称!")
    End If
End If

其中不符合要求时,删除用的这行代码换掉您的 e.Cancel  = True
Sendkeys.SendWait("{Backspace}")

--  作者:良才
--  发布时间:2020/3/14 17:53:00
--  

If PY.IsHanzi(e.KeyChar) OrElse e.keycode = keys.Back Then
Else
    e.Cancel  = True

End If


此主题相关图片如下:qq截图20200314175055.png
按此在新窗口浏览图片

 


 

如果 KeyPress代码
If PY.IsHanzi(e.KeyChar) Then

Else
    e.Cancel  = True

End If
窗口所有控件的 Backspace无用了,请老师指教,谢谢!
[此贴子已经被作者于2020/3/14 18:48:48编辑过]

--  作者:良才
--  发布时间:2020/3/14 21:40:00
--  

老师搞定了

If PY.IsHanzi(e.KeyChar) Then
    If e.sender.Text.Length > 5 Then
        e.cancel = True
    End If
Else If e.keychar = chr(keys.back) Then
Else
    e.Cancel  = True
End If