界面内按回车键自动激活下一个控件
界面内按回车键自动激活下一个控件
版本: 2014-12-30
界面内按回车键自动激活下一个控件, 需要设置
1. this.KeyPreview=true;
2. this.EnterFocusNextControl=true;
frmBase.cs修改代码:
参考文章:
使用SendKeys.Send发送Tab键代替SelectNextControl()方法
扫一扫加作者微信
版本: 2014-12-30
界面内按回车键自动激活下一个控件, 需要设置
1. this.KeyPreview=true;
2. this.EnterFocusNextControl=true;
frmBase.cs修改代码:
C# Code:
/// <summary>
/// 处理回车键或系统热键
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void frmBase_KeyPress(object sender, KeyPressEventArgs e)
{
if ((e.KeyChar == (char)Keys.Enter) &&&& ActiveControl is TextBox &&& (_EnterFocusNextControl))
{
if (ActiveControl is Form) return;
if (ActiveControl != null & ActiveControl is MemoEdit) return;
if (ActiveControl != null & ((TextBox)ActiveControl).Multiline == true) return;
if (ActiveControl != null & ActiveControl is UserControl) return;
if (ActiveControl != null & ActiveControl is GridControl) return;
SendKeys.Send("{Tab}");//发送Tab键
}
else //其它键,作为系统热键处理
{
DoHotkey(e.KeyChar);
}
}
/// <summary>
/// 处理热键
/// </summary>
/// <param name="key"></param>
protected virtual void DoHotkey(char key)
{
if (key == (char)Keys.F1)
{
Msg.Warning("触发frmBase.DoHotkey事件!");
}
}
//来源:C/S框架网(www.csframework.com) QQ:1980854898
/// <summary>
/// 处理回车键或系统热键
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void frmBase_KeyPress(object sender, KeyPressEventArgs e)
{
if ((e.KeyChar == (char)Keys.Enter) &&&& ActiveControl is TextBox &&& (_EnterFocusNextControl))
{
if (ActiveControl is Form) return;
if (ActiveControl != null & ActiveControl is MemoEdit) return;
if (ActiveControl != null & ((TextBox)ActiveControl).Multiline == true) return;
if (ActiveControl != null & ActiveControl is UserControl) return;
if (ActiveControl != null & ActiveControl is GridControl) return;
SendKeys.Send("{Tab}");//发送Tab键
}
else //其它键,作为系统热键处理
{
DoHotkey(e.KeyChar);
}
}
/// <summary>
/// 处理热键
/// </summary>
/// <param name="key"></param>
protected virtual void DoHotkey(char key)
{
if (key == (char)Keys.F1)
{
Msg.Warning("触发frmBase.DoHotkey事件!");
}
}
//来源:C/S框架网(www.csframework.com) QQ:1980854898
参考文章:
使用SendKeys.Send发送Tab键代替SelectNextControl()方法
扫一扫加作者微信
版权声明:本文为开发框架文库发布内容,转载请附上原文出处连接
NewDoc C/S框架网