有时候我们需要使用enter,或arrow key来跳到下一个控件,可是我做怎么样做才实现与Tab一样的校果呢. 很简单,我们只要把窗体的keypreview属性设为true.然后在keyup或所有的keyevent事件里.写上如下的代码:

         private void Form1_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter||e.KeyCode==Keys.Right)
            {
                if (ActiveControl != null)
                {
                    this.SelectNextControl(this.ActiveControl, true, true, true, true);                   
                    //this.SelectNextControl(this.ActiveControl, true, false, false, true);
                    //this.ActiveControl.SelectNextControl(this.ActiveControl, true, false, false, true);
                }
            }      
        }

posted on 2008-11-21 11:46  John.Lau  阅读(527)  评论(0编辑  收藏  举报