laroberts Posted June 29, 2005 Posted June 29, 2005 I have a form that is setup to ask for a user anme and then a password. I would like it if the user could just press enter as soon as they enter the password rather then having to push a login button. I have looked all over the net for a way to do this and have not found one yet. Any help would be great however I am very new to vb.net so please show complete code if you have the answer or I will get lost. :-) Also, I will need to do a if statement in there also to validate the password. Thank you!!! :D Quote
Joe Mamma Posted June 29, 2005 Posted June 29, 2005 no need to trap the keys use DialogResult property of your buttons and form as well as Form.AcceptButton and Form.CancelButton research DialogResult and Modal Forms heres the gist - (assumptions form class is called LogonForm, LogonForm contains text boxes, txtUser, txtPW LogonForm has function Logon(userName, password) as boolean in its scope. drop two buttons on the form, btnOk and btnCancel set the DialogResult on the btnOk button to DialogResult.Ok set the DialogResult on the btnCancel button to DialogResult.Cancel set LogonForm.AcceptButton property to the btnOk button set LogonForm.CancelButton property to the btnCancel button in the closing event: Private Sub Form1_Closing(ByVal sender As Object, _ ByVal e As System.ComponentModel.CancelEventArgs) _ Handles MyBase.Closing if me.DialogResult = DialogResult.Ok then if not Logon(txtUser, txtPW) MessageBox.Show("Logon Failed") e.Cancel = true end if end if End Sub open the form like this - with new LogonForm if .ShowModal() = DialogResult.Cancel then MessageBox.Show("User Cancelled") End .Dispose() end with ' Continue with the rest of your program here Quote Joe Mamma Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized. Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.
michael_hk Posted June 29, 2005 Posted June 29, 2005 http://xtremedotnettalk.com/showthread.php?t=87488 Quote There is no spoon. <<The Matrix>>
Joe Mamma Posted June 29, 2005 Posted June 29, 2005 with new LogonForm if .ShowModal() = DialogResult.Cancel then MessageBox.Show("User Cancelled") End .Dispose() end with ' Continue with the rest of your program here should have read with new LogonForm if .ShowDialog() = DialogResult.Cancel then MessageBox.Show("User Cancelled") End .Dispose() end with ' Continue with the rest of your program here My Delphi crept in there!!! Quote Joe Mamma Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized. Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.