例如,有A,B两窗体,怎么样在B窗中访问到A中的textBox.text的值

解决方案 »

  1.   

    A窗体中:
    B frb=new (this.TextBox.Text);
    frb.ShowDialog();
    B窗体中:
    private string txt;
    public B(string TXT)
    {
    //
    // 
    txt=TXT;
    InitializeComponent(); // Add any initialization after the InitializeComponent() call
    }
    后面就可以对txt(也就是A窗体中的text)进行操作了
      

  2.   

    在b窗体内定义一个属性,a窗体调用b窗体时用textBox.text对b窗体的属性传值.如:
    public class b : System.Windows.Forms.Form
    {
      private string strValue="";
      public string Value
    {
                    set
    {dstReport=value;}
    }
    }private void button1_Click(object sender, System.EventArgs e)//a 窗体中某按钮的单击事件
    {
      b ss=new Rb();
      ss.Value=textBox.text;
      ss.Show();
    }
      

  3.   

    A窗体中:
    在属性中设置 TextBox 访问性 为 public
    B frb=new (this.TextBox);
    frb.ShowDialog();
    B窗体中:
    private string txt;
    public B( TextBox TXT)
    {
    //
    // 
    TextBox txt=TXT;
    InitializeComponent(); // Add any initialization after the InitializeComponent() call
    }
    后面就可以对txt.Text(也就是A窗体中的TextBox.Text)进行操作了
      

  4.   

    直接传递 A 的TextBox 的引用 , 在B 想象对它做什么就做什么!!!!!!!!!!!!!A窗体中:
    在属性中设置 TextBox 访问性 为 public
    B frb=new (this.TextBox);
    frb.ShowDialog();
    B窗体中:
    private TextBox  txt;
    public B( TextBox TXT)
    {
    //
    // 
    TextBox txt=TXT;
    InitializeComponent(); // Add any initialization after the InitializeComponent() call
    }
    后面就可以对txt.Text(也就是A窗体中的TextBox.Text)进行操作了
      

  5.   

    在b窗体内定义一个属性,a窗体调用b窗体时用textBox.text对b窗体的属性传值.如:
    public class b : System.Windows.Forms.Form
    {
      private string strValue="";
      public string Value
    {
                    set
    {dstReport=value;}
    }
    }private void button1_Click(object sender, System.EventArgs e)//a 窗体中某按钮的单击事件
    {
      b ss=new b();
      ss.Value=textBox.text;
      ss.Show();
    }
      

  6.   

    http://blog.csdn.net/zhzuo/archive/2004/04/05/22027.aspx
    非常好的文章,看了就明白是怎么回事了
      

  7.   

    效果:Form1的textBox1的内容变化时Form2的textBox2同步变化。
    //Form2.cs
    public delegate void ChangeText(object sender);
    public ChangeText changeText;changeText = new ChangeText(MyFunc);
    private void MyFunc(object sender)
    {
       textBox2.Text = ((TextBox)sender).Text;
    }
    //Form1.cs
    public Form2 form2;
    private void textBox1_TextChanged(object sender, System.EventArgs e)
    {
      if(form2 != null)
      {
        form2.changeText(sender);
      }
    }private void button1_Click(object sender, System.EventArgs e)
    {
      form2 = new Form2();
      form2.Show();
    }