在一个具有focus的textbox上按 上 enter键,
处理程序如下。        protected override bool ProcessDialogKey(Keys keyData)
        {
            if ( keyData == Keys.Enter)
            {
                MessageBox.Show(ActiveControl.Name);
                //keyData = Keys.Tab;
            }
            return base.ProcessDialogKey(keyData);
        }为何总是Winform上我放的splitContainer1呢?

解决方案 »

  1.   

    为何总是show出 我在form上放的splitContainer1的name呢?
      

  2.   

    你的设置你想show的控件获得focus,把你要获得焦点的控件设置为acrivecontrol才行
      

  3.   

    那不是太麻烦了。有focus的控件不一定是ActiveControl?
      

  4.   

    ActiveContorl控件是Form上TabIndex为0的那个控件吗?
    我的Form上我有两个splitContainer, Show出来的Name总是splitContainer1。
    这样的话,像下面这类代码不是有问题?????
            //protected override bool ProcessDialogKey(Keys keyData)
            //{
            //    if (//( ActiveControl is TextBox || ActiveControl is ComboBox || ActiveControl is DateTimePicker) &&
            //        keyData == Keys.Enter)
            //    {
            //        MessageBox.Show(ActiveControl.Name);
            //        //keyData = Keys.Tab;
            //    }
            //    return base.ProcessDialogKey(keyData);
            //}
            /// </summary>
            /// <param name="msg"></param>
            /// <param name="keyData"></param>
            /// <returns></returns>
            protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
            {
                if (  ((ActiveControl is TextBox)) && (keyData == Keys.Up || keyData == Keys.Down || keyData == Keys.Enter))
                {
                    if (keyData == Keys.Enter)
                    {
                        System.Windows.Forms.SendKeys.Send("{TAB}");
                        return true;
                    }
                    if (keyData == Keys.Down)
                        System.Windows.Forms.SendKeys.Send("{TAB}");
                    else
                        SendKeys.Send("+{Tab}");
                    return true;
                }
                else
                    return base.ProcessCmdKey(ref msg, keyData);
            }
      

  5.   

    别外我在FormLoad事件里加上了this.ActiveControl = empIDTextBox; show出来的还是总是splitContainer1.Name的值。
    有谁能说说ActiveControl属性倒底会在什么时候改变?
    具有Focus的控件怎么不是Activecontrol?