Click here to Skip to main content
15,893,904 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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?
Posted
Comments
Sergey Alexandrovich Kryukov 12-May-15 23:35pm    
The scope of the question is too general to be reasonable.
TextBox? Which one? Full type name, please.
The problem looks extremely simple, you just need to learn events. (I'm afraid you don't have a clue — "keypress function" sounds total gibberish.)
But it would be disgusting to try to answer for all possible application types and UI libraries. Tell us exactly what it is. The simplest way it to tell us exact type, for example, "System.Windows.Forms.TextBox". Or?...
—SA

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."
 
Share this answer
 
v3
Comments
Sergey Alexandrovich Kryukov 13-May-15 0:45am    
You are right. (Probably the message "successful log in, try again" is just the joke. :-) It looks like the inquirer wants to enforce extremely weak passwords.
My 5.
—SA
Peter Leow 13-May-15 3:33am    
Thank you, SA. Actually, that was my typo.:D
Sergey Alexandrovich Kryukov 13-May-15 3:51am    
I would remove () then. :-)
—SA
I understand the following :
You want to create a kind of custom TextBox. For the understanding of this you can use the following code :
VB
    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


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
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 13-May-15 3:52am    
The technique is correct, but the purpose is bad, and the code style... hm...
—SA
Ralf Meier 13-May-15 5:15am    
With the purpose you might be right - I have only answered the question.
But ... what is not good with the code ...?
Sergey Alexandrovich Kryukov 13-May-15 9:34am    
No, nothing realy bad, but perhaps hard-coded immediate constants (0, 1, +, -) could be eliminated; for demo code, this is fine.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900