foreach
(Control ctrl
in
this
.Controls)
{
if ((ctrl is TextBox) || (ctrl is ComboBox)) // 如果文本框或下拉框放在组合框中,你应该用如groupBox1.TextBox
{
ctrl.KeyDown += new System.Windows.Forms.KeyEventHandler( this .EnterKeyDown);
}
}
然后在EnterKeyDown事件中定义当按下的键为Enter键时,发送Tab键,程序如下:{
if ((ctrl is TextBox) || (ctrl is ComboBox)) // 如果文本框或下拉框放在组合框中,你应该用如groupBox1.TextBox
{
ctrl.KeyDown += new System.Windows.Forms.KeyEventHandler( this .EnterKeyDown);
}
}
private
void
EnterKeyDown(
object
sender, System.Windows.Forms.KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
System.Windows.Forms.SendKeys.Send( " {TAB} " );
}
}
{
if (e.KeyCode == Keys.Enter)
{
System.Windows.Forms.SendKeys.Send( " {TAB} " );
}
}