不知道你要传什么,有一个方法,你自己看看符合你的要求不. 假如窗体A\窗体B,B中默认的构造函数默认为 public B() { InitializeComponent(); } 你改为 public B(string str) { InitializeComponent(); B.combox.Text = str; } 在A中调用 Form B = new Form(A.combox.Text); b.Show(); 这样B的控件显示的值就和A的一样了,我记得是这么写的,你自己试验一下吧。想传别的就按这个意思传。
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms;namespace WindowsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { string name=this.textBox1.Text; Form2 frm = new Form2(name); frm.Show();
}
} } ----------------------------------------------------------------- using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms;namespace WindowsApplication1 { public partial class Form2 : Form { public Form2(string b) { InitializeComponent(); this.textBox1.Text = b; } } }
假如窗体A\窗体B,B中默认的构造函数默认为
public B()
{
InitializeComponent();
}
你改为
public B(string str)
{
InitializeComponent();
B.combox.Text = str;
}
在A中调用
Form B = new Form(A.combox.Text);
b.Show();
这样B的控件显示的值就和A的一样了,我记得是这么写的,你自己试验一下吧。想传别的就按这个意思传。
Windows窗体间的数据交互
http://blog.csdn.net/zhzuo/archive/2004/04/05/22027.aspx
窗体的参数传递
http://blog.csdn.net/zhzuo/archive/2006/05/05/708941.aspx#sec5
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void button1_Click(object sender, EventArgs e)
{
string name=this.textBox1.Text;
Form2 frm = new Form2(name);
frm.Show();
}
}
}
-----------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace WindowsApplication1
{
public partial class Form2 : Form
{
public Form2(string b)
{
InitializeComponent();
this.textBox1.Text = b;
}
}
}