假设我现在写界面Form1,界面上有一个按扭butten1,点击后会弹出另一个界面Form2,Form2中有一个textBox和一个button,当在textbox中输入之后,点击button,我想在form1中显示输入的值,这个不用static,还有什么好办法吗?

解决方案 »

  1.   

    public partial class Form1 : Form   
      {   
      private void button1_Click(object sender, EventArgs e)   
      {   
      Form2 frm2 = new Form2();   
      frm2.Show(this);   
      }   
      }     public partial class Form2 : Form   
      {   
      private void button1_Click(object sender, EventArgs e)   
      {   
      Form1 frm1 = (Form1)this.Owner;   
      ((TextBox)frm1.Controls["textBox1"]).Text = this.textBox2.Text;   
      this.Close();   
      }   
      }   
      

  2.   

    楼上的就可以  
    你也可以这样写 
    //Form1
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;namespace TestShow
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
            public Form1(string str)
            {
                InitializeComponent();
                this.label1.Text = str;
            }
         private void button2_Click(object sender, EventArgs e)
            {
                Form2 fr2 = new Form2();
                fr2.Show();
                this.Visible = false;
            }
    //=========================
    //Form2
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;namespace TestShow
    {
        public partial class Form2 : Form
        {
            public Form2()
            {
                InitializeComponent();
            }
            private void button1_Click(object sender, EventArgs e)
            {
                Form1 fr1 = new Form1(textBox1.Text);
                fr1.Show();
                this.Visible = false;
            }
        }
    }
      

  3.   

    http://topic.csdn.net/u/20100907/16/d4cdd18a-b24d-48f9-a9e5-43baf6a5ebb1.html#top
      

  4.   

    那假如我还想对Form1中得到的那个数据进行处理呢,也要在button1_Click()这个方法中进行的,也就是说我这个按钮不仅仅要得到那个数据,还要进行一定的运算,这个怎么办?谢谢。
      

  5.   


    先运算  再赋值如果你用如梦大哥的方法就是这样的 public partial class Form2 : Form  
      {  
      private void button1_Click(object sender, EventArgs e)  
      {  
      Form1 frm1 = (Form1)this.Owner;  
      string str="";
      //做运算,比如加上"--CSDN"
      str=this.textBox2.Text+"--CSDN";
      ((TextBox)frm1.Controls["textBox1"]).Text = str;  
      this.Close();  
      }  
      }