Windows Develop Bookmark and Share   
 index > Windows Forms General > AS soon as user hits Enter tab while typing password submit button get focus
 

AS soon as user hits Enter tab while typing password submit button get focus

Hi All,

I am Using VS03 + C# + Windows

In my application i want when user type password and after completion hits Enter Button then submit button

get focus.

Below what i have tried

private void txtPassword_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e)

{

if(txtPassword.Text.Length != 0)

{

btnUser.Focus();

}

}

But here problem is that button get focus every time after key release.

Anyone give me suggestion.

The code in c# is apriciated.

Thanks in advance.

sunDAC  Thursday, June 05, 2008 7:05 AM

Hi,

Just set the AcceptButton property of the form to the button. When the user hits enter, the button will fire.

If that doesn't help, try to override the ProcessCmdKey virtual method as shown over here

HTH,

Suprotim Agarwal

Suprotim Agarwal  Thursday, June 05, 2008 7:23 AM
click on your form and set the AcceptButton property (VS2008 but should be similar for 03)


or perhaps you might need to set your controls TabIndex properties.. last resort hack it using SendKeys with a Tab
Meaning Of Lights  Thursday, June 05, 2008 7:13 AM

Hi,

Just set the AcceptButton property of the form to the button. When the user hits enter, the button will fire.

If that doesn't help, try to override the ProcessCmdKey virtual method as shown over here

HTH,

Suprotim Agarwal

Suprotim Agarwal  Thursday, June 05, 2008 7:23 AM

Hi Suprotim Agarwal,

Thanks for the reply.I simply set the AcceptButton property of the form to the button and it get works fine.

I also tried and capture the enter key for button, it also works fine .

Below is my code

private void txtPassword_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)

{

if(txtPassword.text.Length !=0)

{

btnSubmit.focus();

}

}

Thanks.

Cheers!

sunDAC  Thursday, June 05, 2008 7:58 AM



san7481wrote:
"Thanks for the reply.I simply set the AcceptButton property of the form to the button and it get works fine."


Its cool you must have looked at the last reply to your question. In future and for the record I answered it first.

Moderators this is a little off putting.
Meaning Of Lights  Thursday, June 05, 2008 9:53 AM

You can use google to search for other answers

Custom Search

More Threads

• Check items in toolstripcombobox
• 3tier dataflow/communication
• Taskbar and SYSTray
• How to pass VBA collection to VB Com Component?
• Web browser list & setings...
• Referencing Windows Form from another Project
• How to include MSDE with MSI
• Should be a simple math alteration
• How to bind a DataGridViewComboBoxColumn to an object rather than a value!
• Visual Source Safe Hell