Code Block
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
Button button = new Button();
button.Bounds = new Rectangle(0, 0, 100, 30);
this.Controls.Add(button);
TestUserControl userControl = new TestUserControl();
userControl.Bounds = new Rectangle(110, 0, 300, 300);
this.Controls.Add(userControl);
TextBox txtBox = new TextBox();
txtBox.Bounds = new Rectangle(420, 0, 100, 30);
this.Controls.Add(txtBox);
}
}
class TestUserControl:UserControl
{
TextBox textBox1;
Button button1;
TextBox textBox2;
public TestUserControl()
{
this.textBox1 = new TextBox();
this.textBox1.Bounds = new Rectangle(3, 3, 100, 20);
this.textBox1.KeyDown += new KeyEventHandler(textBox1_KeyDown);
this.button1 = new Button();
this.button1.Bounds = new Rectangle(3, 29, 75, 23);
this.textBox2 = new TextBox();
this.textBox2.Bounds = new Rectangle(3, 58, 100, 20);
this.textBox2.KeyDown += new KeyEventHandler(textBox2_KeyDown);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.button1);
this.Controls.Add(this.textBox2);
}
void textBox1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
this.textBox1.FindForm().GetNextControl(this.ActiveControl, true).Focus();
}
void textBox2_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
this.textBox2.FindForm().GetNextControl(this.ActiveControl, true).Focus();
}
}