回车移动焦点

///// <summary>
        ///// 回车到下一行
        ///// </summary>
        ///// <param name="aKey"></param>
        ///// <returns></returns>
        //protected  override   bool ProcessDialogKey(System.Windows.Forms.Keys aKey)
        //{
        //    if (aKey == Keys.Enter)
        //    {
        //        SendKeys.Send("{TAB}");
        //        return true;

        //    }
        //    return base.ProcessDialogKey(aKey);
        //} 

        /// <summary>
        /// 按键处理
        /// </summary>
        /// <param name="msg">按键消息</param>
        /// <param name="keyData">按键数据</param>
        /// <returns></returns>
        protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
        {
            //判断:
            //  按键是否为[Enter]
            if (keyData == Keys.Enter)
            {
                //成立执行
                //判断:
                //活动控件不是System.Windows.Forms.TextBox或System.Windows.Forms.TextBox继承类
                // 或
                //   活动控件是System.Windows.Forms.TextBox或System.Windows.Forms.TextBox继承类但不接受[Enter]
                //if (
                //    //!(ActiveControl is System.Windows.Forms.TextBox) ||
                //    ((System.Windows.Forms.TextBox)ActiveControl).AcceptsReturn == false
                //    )
                {
                    //成立执行
                    //模拟按下[Tab]
                    SendKeys.SendWait("{Tab}");

                    //截停[Enter]消息
                    return true;
                }
            }

            //判断
            //  按键是否为[Shift+Enter]
            if (keyData == (Keys.Enter | Keys.Shift))
            {
                //成立执行
                //模拟按下[Shift+Tab]
                SendKeys.SendWait("+{Tab}");

                //截停[Shift+Enter]消息
                return true;
            }
            //非按下[Enter]继续处理
            return base.ProcessCmdKey(ref msg, keyData);
        }       

posted @ 2013-12-16 10:10  Net-Spider  阅读(160)  评论(0编辑  收藏  举报