1

My app has four group boxes with four text boxes and one button in each group box what i would like to do is use the keyboard enter button to tab instead of the tab button and when it gets to my control button instead of left clicking the mouse to activate my control button I would like to press the enter key on the keyboard to activate it has anyone got any ideas how to do this

2
Contributors
1
Reply
2
Views
11 Years
Discussion Span
Last Post by r0ckbaer
0

Don't know if i understood exactly what you mean, but i guess you want to simulate the TAB button behaviour with the ENTER button, to do this you can do the following (might be buggy and inefficient because quickly tested):

First you have to add keydown events to every control in your form (i assume your Form is called Form1):

private void Form1_Load(object sender, System.EventArgs e)
		{
			AddEnterEvent((Control)sender);
		}

private void AddEnterEvent(Control c)
		{
			c.KeyDown += new KeyEventHandler(c_KeyDown);

			foreach (Control ctlChildren in c.Controls)
			{
				AddEnterEvent(ctlChildren);
			}	
		}

The keydown event code:

private void c_KeyDown(object sender, KeyEventArgs e)
		{
			if (e.KeyCode == Keys.Enter)
			{
				Control ctlNext = ActiveForm.GetNextControl((Control)sender, true);
				ctlNext.Focus();
			}
		}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.