zoukankan      html  css  js  c++  java
  • 变Enter键为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;
                }
            }

        }
  • 相关阅读:
    RESTful API入门
    $.ajax()参数详解及标准写法(转)
    Jquery 页面首次加载方式
    jQuery操作单选按钮(radio)用法
    GridView的 OnRowDataBound 事件用法
    ASP.NET文件上传大小的限制解决方案
    jQuery经典学习笔记
    Thermal management in a gaming machine
    iis7配置网站容易出现的问题(转)
    你能熟练使用Dictionary字典和List列表吗?(转)
  • 原文地址:https://www.cnblogs.com/moss_tan_jun/p/1820815.html
Copyright © 2011-2022 走看看