如何为Keypress创建编码?(Visual Basic 2012 Oop方法) [英] How Do I Create Coding For Keypress?(Visual Basic 2012 Oop Method)
问题描述
我想使用visual studio 2012和SQL Server 2012创建一个注册表单。
我想要的功能是:
- 如果我在用户名的文本框中输入一个数字,程序会警告我用户名只能包含字母。
- 在密码文本框如果我输入一个字母,程序会警告我密码只能包含字母。
i听说这样做是为了使用按键功能。
按键执行上述功能的代码是什么?
I want to create a register form using visual studio 2012 and SQL server 2012.
the function i want is:
- if i type a number on the textbox for username the program will warn me that the username can only contain letter.
- in the password textbox if i type a letter the program will warn me that the password can only contain letter.
i heard that to do this is to use keypress function.
what is the coding for keypress to do a function like above?
推荐答案
永远不要这样做!你正在促进黑客攻击。如果您是帐户的真实所有者,则不需要此帐户。如果你不是,那么你也不需要这个。
如果是拼写错误,只需说(联合国)成功登录,再试一次。
Never do that! You are facilitating hacking. If you are the authentic owner of an account, you do not need this. If you are not, then you do not need this either.
in case of typo, just say "(un)successful log in, try again."
我理解以下内容:
您想要创建一种自定义TextBox。为了解这一点,您可以使用以下代码:
I understand the following :
You want to create a kind of custom TextBox. For the understanding of this you can use the following code :
Public Class myTextBox
Inherits System.Windows.Forms.TextBox
Protected Overrides Sub OnKeyDown(ByVal e As System.Windows.Forms.KeyEventArgs)
Dim Taste As Keys = e.KeyCode
Select Case Taste
Case Keys.Enter, Keys.Escape
'Input Complete
e.Handled = True
Case Else
Beep()
e.Handled = True
End Select
End Sub
Protected Overrides Sub OnKeyPress(ByVal e As System.Windows.Forms.KeyPressEventArgs)
Dim Taste As Char = e.KeyChar
Select Case Taste
Case "0" To "9"
' do something
Case "+"
' do something
Case "-"
' do something
Case ".", ","
' do something
End Select
e.Handled = True
End Sub
end class
在你可以做的,你想象的(或者想想会发生什么)你可以做的事情。
结果是你有自己的spezifiedTextBox继承自标准 - TextBox ...
问候
Ralf
Inside the overrided Sub's you could do, what you imagine (or think what shall happen).
The Result is that you have you own "spezified" TextBox which inherits from the Standard-TextBox ...
Greetings
Ralf
这篇关于如何为Keypress创建编码?(Visual Basic 2012 Oop方法)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!