如题 在form1中存在3个textbox,并存在数值,然后通过一个button,打开form2并且把这3个值,付给form2中的3个textbox!
请问如何做?

解决方案 »

  1.   

    參見
    http://blog.csdn.net/tjvictor/archive/2006/06/23/824617.aspx
      

  2.   


            private void button1_Click(object sender, EventArgs e)
            {
                Form2 frm2 = new Form2(this);
                frm2.Show();
            }        public void Test()
            {
                textBox1.Text = "aaaa";
            }
    ******************************
     public partial class Form2 : Form
        {
            Form1 frm;        public Form2(Form1 _frm)
            {
                InitializeComponent();
                frm=_frm;
            }        private void button1_Click(object sender, EventArgs e)
            {
                frm.Test();
            }        private void button2_Click(object sender, EventArgs e)
            {
                frm.textBox1.Text = textBox1.Text;
            }
        }
      

  3.   

    楼上的代码是传了整个form给form2,你还可以只把form1的textbox传给form2,
    默认为引用传递,所以很好控制
      

  4.   

    在form1定义3个静态变量,然后再form2操作改变,也可以实现。
      

  5.   

    在form1定义3个静态变量,然后再form2操作改变,也可以实现。
      

  6.   

    oniu828的明显违反迪米特原则,还是让form2公开个方法来接收这三个值吧。
      

  7.   

    private void Clearbtn_Click(object sender, EventArgs e)
            {
                clear frm = new clear(this.textBox1.Text,this.textBox2.Text,this.textBox3.Text);
                
                frm.Show();
                
            }
            public clear(string tbS1,string tbS2,string tbS3)
            {
              
                InitializeComponent();
                this.textBox1.Text = tbS1;
                this.textBox2.Text = tbS2;
                this.textBox3.Text = tbS3;
            }
           
    这样解决的  对吗?
      

  8.   

    在form2类中设一个public 变量 a,在form1中 
    form2 b=new form2();
    b.a=this.textbox1;
    b.show();
      

  9.   

    namespace xx
    {  public partial class test: Form
    {
      form2.x=.............
    }
     
    }
      

  10.   

    (1) 使用替換控制權來進行傳遞
    Form1_button1_click
    value_transfer.Form2 myfrm=new Form2("ttt");
    myfrm.Owner=this;
    myfrm.ShowDialog();Form2_button2_click
    //通過移交控制權來傳遞參數
     value_transfer.Form1 myfrm=new Form1();
    myfrm=(Form1)this.Owner;
    myfrm.textBox1.Text=this.textBox1.Text;
    //myfrm.textBox1.Text=myfrm.add(3,5).ToString();
    //add和myfrm.textBox1設置成PUBLIC才可以訪問的。(2) 通過FORM. DialogResult來進行參數傳遞
    Form1_button1_click
    value_transfer.Form2 myfrm=new Form2();
    if (myfrm.ShowDialog()==System.Windows.Forms.DialogResult.OK)
    {
    this.textBox1.Text =myfrm.textBox1.Text;
    }Form2_button1_click
    this.DialogResult=System.Windows.Forms.DialogResult.OK;(3) 通過類的屬性來傳遞參數
    //建立公共類庫
    Public class test()
    {
    //設置私有靜態字符類型
      Private static string temp;
      Public class test()
    {}
      
       Public string s
       {
         Set 
            {this.temp=values;}
         Get
          {return this.temp;}Form2_button1_click
    value_transfer.Class1 myclass=new Class1();
    myclass.test=this.textBox1.Text.Trim();Form1_button1_click
    value_transfer.Class1 myclass=new Class1();
    this.textBox1.Text=myclass.test;(4) 窗體傳遞參數
    FORM2(STRING ADB);
      

  11.   

    供参考,如下:
    我的Form1是父窗体
    Form2是子窗体
    每个窗体里包含一个ListBox
    然后根据Form1里的ListBox的选值改变Form2里Listbox的选值
    ListBox里我设置的是1,2,3,4,5,6 6个值然后可以对应改变
    Form1代码如下:
    Public Class Form1    Private Sub ListBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.Click
            Form2.ListBox1.SelectedItem = Me.ListBox1.SelectedItem
        End Sub    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Form2.Show()    End Sub
    End Class
    Form2代码如下:
    Public Class Form2    Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Me.MdiParent = Form1
            
        End Sub
    End Class
      

  12.   

    最痴呆的方法就是把控键变为public,然后在form1里面声明form2的变量,调用form2.text1.text
      

  13.   

    form2 f=new form2(this.textbox1.text,this.textbox2.text,this.textbox3.text)
    f.show();
    在form2 中定义
    public Form1(string str1,string str2,string str3)
            {
                InitializeComponent();
                this.textbox1.text=str1;
                this.textbox2.text=str2;
                this.textbox3.text=str3;
            }