Reputation: 1290
Hopefully there is a pretty easy solution to this.
I have a program where the user has to click next a lot to move through a setup process.
What's the best way to maintain focus on the next button while the user enters info in text boxes?
Upvotes: 0
Views: 91
Reputation: 1069
A way around is handling the return key for each text box. So when the user presses enter key, it can simulate pressing next button.
First move your code in the next button to a void.
private void GoNext()
{
//Do something
}
private void btnNext_Click(object sender, EventArgs e)
{
GoNext();
}
Now handle the key press.
private void textBox1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Return)
{
e.Handled = true;
GoNext();
}
}
You may also draw focus rectangle in the lost focus event of next button for visual purposes.
Upvotes: 0
Reputation: 13600
Well, that depends on the design, but it shouldn't be a problem marking your button as "default". In winforms it's called "AcceptButton" if I'm not mistaken.
http://msdn.microsoft.com/en-us/library/system.windows.forms.form.acceptbutton%28v=VS.100%29.aspx
Upvotes: 2