Member Avatar for aabbccbryanmark_1
Private Sub txtPassword_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtPassword.KeyPress
Dim NotAllowed As String = "~`@%^&+={[}]()!:,;'><?/|\-.#+()_$*"

    If e.KeyChar = ChrW(Keys.Enter) Then
        e.Handled = True
    End If

    If e.KeyChar <> ControlChars.Back = True Then
        If NotAllowed.IndexOf(e.KeyChar) = -1 = False Then
            e.Handled = True
        End If
    End If
End Sub

hi guys i just wanna ask if this code is true and makes the enter key null

Hi,
Yes e.handled = true will stop the character.

Member Avatar for aabbccbryanmark_1

ow, so its true, but why when i test i still key enter is not stop,
btw i wanna ask if enter key can be prevented from LoginForm or not?

If you don't want anything happen on the key enter just don't use it.

 Private Sub TextBox1_KeyPress(sender As Object, e As KeyPressEventArgs) Handles TextBox1.KeyPress
        Dim NotAllowed As String = "~`@%^&+={[}]()!:,;'><?/|\-.#+()_$*"
        If e.KeyChar <> ControlChars.Back = True Then
            If NotAllowed.IndexOf(e.KeyChar) = -1 = False Then
                e.Handled = True
            End If
        End If
    End Sub

Seems to work fine; are you setting the Handle to the right control?

Private Sub txtPassword_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles [Your_Control_Name].KeyPress
Member Avatar for aabbccbryanmark_1

@minimalist
well what i want is that when someone press the enter key for loginform it will not work
@atove
the control name is the txtPassword?

As per the code you've posted above; thats right. Unless you've named the textbox control for your password field to something else. Otherwise i've tested this and its handling enter and preventing it from returning a line within a multiline textbox.

Is there perhaps another sub thats catching the enter keypress event when its pressed on the loginform?

Member Avatar for aabbccbryanmark_1

@atove
no only there, btw is it ok to prevent enter key in a login form or not?

Member Avatar for aabbccbryanmark_1

http://i476.photobucket.com/albums/rr128/ceu09/Untitled_zps26ce6e83.jpg

here is my window for login, btw is it normal that the login button is colored blue?, maybe that's the one that's bothering my problem, even though i put codes they wont work because of it, so now im asking if theres a way that i can remove the blue outline thing on the button

Member Avatar for aabbccbryanmark_1

Solved by deleting the old button and replacing it with a new one

Ahh. By default your Login button is focused. So when enter is pressed its clicking the button. You need to handle the enter press event on the login button. But instead you could set the default focus to be one of your textbox controls instead. Just set the TabIndex property of one of those to 0 which would also remove the highlighting as the button would not have default focus.

I don't know of a way off the top of my head to remove the highlighting on the button. Its apart of the windows interface to show that a button has focus. Really its something that should be shown to indicate to the user what they currently have focused.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.