WinForm中变Enter键为Tab键实现焦点转移的方法
2018-01-02 17:33
477 查看
if (e.KeyCode == Keys.Enter) { //this.SelectNextControl(this.ActiveControl,true, true, true, true); SendKeys.Send("{Tab}"); //向活动应用程序发送击键 注意格式:Send("{Tab}");中的{} }
/// <summary> /// 窗体控件控制相关的方法 /// </summary> public class ControlTools { private Form frm; public ControlTools(Form frm) { this.frm = frm; } /// <summary> /// 窗体上所有子控件的回车设成Tab /// </summary> public void EnterToTab() { frm.KeyPreview = true; frm.KeyPress += new KeyPressEventHandler(frm_KeyPress); } /// <summary> /// 注册窗体的KeyPress事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void frm_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == (char)Keys.Enter) { frm.SelectNextControl(frm.ActiveControl, true, true, true, true); } } /// <summary> /// 把某一个控件的所有子控件(TextBox ComboBox)的回车设成Tab /// </summary> /// <param name="groupControl">容器控件</param> public void EnterToTab(Control groupControl) { foreach (Control control in groupControl.Controls) { if (control is TextBox || control is ComboBox) control.KeyPress += new KeyPressEventHandler(control_KeyPress); } } /// <summary> /// 注册控件的KeyPress事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void control_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == 13) { SendKeys.Send("{Tab}"); e.Handled = false; } } }
来源参考:
http://www.phpstudy.net/b.php/100776.html WinForm中变Enter键为Tab键实现焦点转移的方法
http://blog.csdn.net/jameshelong/article/details/11947549 在winform窗口上,实现按回车键(Enter)光标移至下一个控件的方法
相关文章推荐
- WinForm中变Enter键为Tab键实现焦点转移的方法
- WinForm中 变Enter键为Tab键 实现焦点转移
- 变Enter键为Tab键 实现焦点转移
- form表单填写,enter键实现tab键的下一个input获得焦点实现
- MFC CTabCtrl焦点转移PreTranslateMessage实现方法
- 用ENTER键模拟TAB键,实现焦点在每个控件里逐一跳转
- C#在WinForm和Web中实现回车键代替TAB键切换控件焦点
- C#在WinForm和Web中实现回车键代替TAB键切换控件焦点
- 如何用<Enter>键代替<Tab>键实现光标焦点转移?
- winform md5加密实现方法
- 用回车键实现MFC对话框中TAB键控制输入焦点在控件中跳转的效果
- 用户体验测试的自动化实现 - 第二种检查Tab顺序的方法
- C# winform程序实现分页的三种方法
- Winform程序多语言国际化实现的简单方法
- 用网页代码实现把TAB键变为Enter键
- [ZT]文本框(input)获取焦点(onfocus)时样式改变的实现方法
- 让Enter键实现Tab键的功能
- Visual C++中Tab View的多种实现方法
- 页面捕获Enter键实现Tab键移动功能(指定特定的控件)
- [导入]Winform程序多语言国际化实现的简单方法