C# Winform 按回车键查找下一个可设置焦点的组件
作者:C/S框架网  发布日期:2013-01-07 14:15:01
  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/S框架网(www.csframework.com) QQ:1980854898



方式二:可特殊处理


C# Code:


Control current = this.GetNextControl(this.ActiveControl, true);
while (true)
{
   if (current.CanFocus && current.CanSelect)
   {
      current.Focus();
      break;
   }
   current = this.GetNextControl(current, true);
}

//来源:C/S框架网(www.csframework.com) QQ:1980854898


上一篇 下一篇