form1有一个button 和textBox,点button调用form2,form2返回一个值给form1的textBox,如何让form2调用结束时form1能将结果在form1的textBox中显示出来?
  我在form1中定义了一个static 的变量temp,将temp的值赋给textBox。在form2中改变temp的值,但是无法在form1中立即显示改变后的textBox的值,怎么办?

解决方案 »

  1.   

    你这是不是。NET问题???
    怎么可能会有两个 FORM
      

  2.   

    temp 不用定义成static,定义成public 就可以了.
    Form2 dlg = new Form2();
    dlg.ShowDialog();
    this.textBox1.Text = dlg.temp;
      

  3.   

    用Delegate
    比如Form1和Form2都各有一个button1, textBox1。
    点击Form2的button1时把Form2的textBox1的内容显示到Form1的textBox1里。// Form1
    namespace WindowsApplication1
    {
        public delegate void SetTextDelegate(string str); //声明一个SetTextDelegate类型的delegate
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }        private void button1_Click(object sender, EventArgs e)
            {
                Form2 frm2 = new Form2();
                frm2.setTextDelegate += new SetTextDelegate(this.SetText);
                frm2.ShowDialog();        }
            private void SetText(string str)
            {
                this.textBox1.Text = str;
            }
        }
    }//Form2
    namespace WindowsApplication1
    {
        public partial class Form2 : Form
        {
            public SetTextDelegate setTextDelegate;
            public Form2()
            {
                InitializeComponent();
            }        private void button1_Click(object sender, EventArgs e)
            {
                if (setTextDelegate != null)
                    setTextDelegate(this.textBox1.Text);
            }
        }
    }
      

  4.   

    form2中赋值temp=Form2.textBox1.text,在form1中赋值Form1.textBox.text = temp.但是temp初始值为空,点击form1的button后无法在Form1.textBox中立刻改变其值。问题就是将语句Form1.textBox.text = temp写在哪个地方才能在点击button后立刻显示Form1.textBox改变后的值。(form1调用form2对象完毕后仍显示原来form1的对象,而不是新建一个form1的对象)