画面上有如下控件:日期1______  数字1________
日期2______  数字2________
日期3______  数字3________
                 
                  退出按钮问题:
  假设我原来在入力[数字2],然后点[退出按钮]后会提示[是否确定退出?]信息,
如果我点[否],如何让焦点回到任意一个之前所在的控件([数字2])?

解决方案 »

  1.   

    >win 还是 web
    不好意思,没说清楚,win的
      

  2.   

    定义一个全局变量的foucsControl当进入控件的时候(enter事件),写上foucsControl= (Control)sender;就是把当前是哪个控件记录下来在按了按扭并选择了否之后:foucsControl.Foucs()
    应该就可以了
      

  3.   

    回juge001:
     多谢你的建议,可是我这个画面上面有200多个完全不同的控件阿,
    而且不象我举的例子那样都是类似的控件哦。倒霉。
      

  4.   


        TextBox lastEditting = null;
        void OnTextBoxLeft(object sender, EventArgs e)
        {
            lastEditting = sender as TextBox;                      //<---
        }    private void Form1_Load(object sender, EventArgs e)
        {
            //TextBox textBox1;
            //TextBox textBox2;
            textBox1.LostFocus += OnTextBoxLeft;
            textBox2.LostFocus += OnTextBoxLeft;
        }    protected override void OnFormClosing(FormClosingEventArgs e)
        {
            if (MessageBox.Show("quit?", null, MessageBoxButtons.OKCancel) == DialogResult.Cancel)
            {
                e.Cancel = true;
                if (lastEditting != null)
                {
                    lastEditting.Focus();
                    lastEditting.SelectAll();
                }        }
        }
      

  5.   

    有200多个完全不同的控件阿    class MyTextBox : TextBox
        {
            protected override void OnLostFocus(EventArgs e)
            {
                (this.Parent as Form1).lastEditting = this;
                base.OnLostFocus(e);
            }
        }
      

  6.   

    给数字2加上 onblur="focblur(this);"事件,在js代码里定义一个变量记住是哪个控件触发的事件
    var textobj;
    function focblur(ob){
    textobj = ob;
    }然后点击退出按钮时,代码如下
    function dd(){
    if(confirm("是否确定退出?")==false)
          textobj.focus();
    }
      

  7.   


    //winform
    thisExitButton_Click(sender,e)
    {
    string message = "是否确定退出?";
            string caption = "";
            MessageBoxButtons buttons = MessageBoxButtons.YesNo;
            DialogResult result;
            result = MessageBox.Show(this, message, caption, buttons,
                MessageBoxIcon.Question, MessageBoxDefaultButton.Button1, 
                MessageBoxOptions.RightAlign);        if(result == DialogResult.No)
            {
                // Focus
                UserCountrol.Focus();
            }
            else
            {
               //点击是的操作
            }}
      

  8.   

    private void 退出按钮_Click(object sender, EventArgs e)
            {
                if (MessageBox.Show("Exit", "", MessageBoxButtons.YesNo) == DialogResult.No)
                    c.Focus();
                else
                    this.Close();
            }
            Control c;
            private void 退出按钮_MouseEnter(object sender, EventArgs e)
            {
                c=this.ActiveControl;
            }
      

  9.   

    多谢大家的解答。
    尝试了一下大家的建议,感觉h_w_king的方案非常不错,开销和代码都最省,多谢了。感谢大家的参与,结贴!
      

  10.   

    >控件多不也一样的实现方法?有什么问题?
    控件多,我得每一类控件都要加一个事件,累。>对了,顺便问下楼方,你这么多控件.呈现的时候,有闪的现象吗?
    有,不过不明显。