我在winfrom里有个文本框,然后我想加载上来的时候文本框里有值然后我点击后没有值当我点别的文本框时候这个文本框里的值在回来,我知道是获得焦点和丢失焦点的问题但是我在winfromm里没有找到呀,求助怎么办?

解决方案 »

  1.   


    public Form2()
            {
                InitializeComponent();
                this.textBox1.Focus();
                this.textBox2.Text = "测试数据";
                this.label1.Visible = false;
                
                this.textBox2.Enter += new EventHandler(Textbox1_OnFocus);
                this.textBox2.LostFocus += new EventHandler(Textbox1_LostFocus);
            }
            private void Textbox1_OnFocus(object sender, EventArgs e)
            {
                //MessageBox.Show("获得焦点");
                this.label1.Text = this.textBox2.Text;
                this.textBox2.Text = "";
            }
            private void Textbox1_LostFocus(object sender, EventArgs e)
            {
                //MessageBox.Show("失去焦点");
                this.textBox2.Text = this.label1.Text;
            }具体的例子,你看一下
      

  2.   

    做一下判断,
    if(this.label1.Text !=this.textBox2.Text)
    this.label1.Text = this.textBox2.Text;
                this.textBox2.Text = "";