Problem with KeyUp/Msgbox

John Cassell

Well-known member
Joined
Mar 20, 2007
Messages
65
Programming Experience
Beginner
Hi,

I am having a problem with one of my forms and was hoping someone could help..

It is a login form and when someone has entered their password and pressed Enter it should either a) log them in or b) tell them their password is wrong.

This works ok but when the msgbox comes up to say 'Incorrect Password' the user presses Enter (as they would do naturally) only to be presented with the msgbox again saying 'Incorrect Password'. To avoid this they need to press the space bar or use the mouse which I would prefer them not to do. My code is below any help would be appreciated..

VB.NET:
Private Sub PasswordTextBox_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles PasswordTextBox.KeyUp
        If e.KeyCode = Keys.Enter Then
            LoginProcedure() ' Which checks the password etc and displays msgbox if needed
        End If
    End Sub
 
What I would do is add a label to the form, if the password is wrong, set the label's visible property to True and clear the password textbox and set focus to it. This way there's a message on the screen to tell them the password was incorrect, but they can also immediately try again without dismissing a messagebox
 
Thanks for that, A label was one of my initial thoughts but I kinda like the idea of a box hitting the user in the face. No big deal if I hav to go down that route but thanks for the reply..

What is the ErrorProvidor component?

Thanks

John
 
ErrorProvider component, you can add one from toolbox to form and configure it, it is used to give in-form feedback to user when validating values of input controls (like your textbox) and when you set an error text it displays a blinking error icon next to the control, if users mouse it a tooltip displays this error message. Validating event is normally used. For example:
VB.NET:
If passwordOK() Then
    Me.ErrorProvider1.SetError(sender, "wrong password")
Else
    Me.ErrorProvider1.SetError(sender, "") 'removes error icon
End If
Type "ErrorProvider" in your help files to get more info.
 
Thanks a lot John, This is very useful. I wouldn't imagine my users would think to hover over the icon but I do like how it is in your face so I am going to use it in conjunction with a label.

Thanks very much for your help and to you, Juggalo.

Regards

John
 
You don't like the ErrorProvider component?

ErrorProvider component, you can add one from toolbox to form and configure it, it is used to give in-form feedback to user when validating values of input controls (like your textbox) and when you set an error text it displays a blinking error icon next to the control, if users mouse it a tooltip displays this error message. Validating event is normally used. For example:
VB.NET:
If passwordOK() Then
    Me.ErrorProvider1.SetError(sender, "wrong password")
Else
    Me.ErrorProvider1.SetError(sender, "") 'removes error icon
End If
Type "ErrorProvider" in your help files to get more info.

I didn't know about that control, thanks for informing me
 
Back
Top