C# Winform 按回车键查找下一个可设置焦点的组件
C# Winform 按回车键查找下一个可设置焦点的组件方式一:
C# Code:
private void frmLogin_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == (Char)Keys.Enter)
{
this.SelectNextControl(this.ActiveControl, true, true, true, true);
e.Handled = true;
}
}
方式二:可特殊处理
C# Code:
Control current = this.GetNextControl(this.ActiveControl, true);
while (true)
{
if (current.CanFocus && current.CanSelect)
{
current.Focus();
break;
}
current = this.GetNextControl(current, true);
}
扫一扫加作者微信