public string UserName
{
get
{
return textBox1.Text;
}
set
{
textBox1.Text = value;
}
}
private void menuItem2_Click(object sender, EventArgs e)
{
//more information
Form2 f = new Form2();
Form1 fr = new Form1();
f.Show();
f.UseName = fr.UserName;
}
在form2中
public string UseName;
private void Form2_Load(object sender, EventArgs e)
{
textBox3.Text = String .Format ("hello,{0}",UseName);
}
但是没有将我在form1中的textBox1的内容给form2 的textBox3加以显示
请指教
------解决方案--------------------
我猜你是想说:
1. 这是form1的代码
- C# code
public string UserName { get { return textBox1.Text; } set { textBox1.Text = value; } } private void menuItem2_Click(object sender, EventArgs e) { //more information Form2 f = new Form2(); Form1 fr = new Form1(); f.Show(); f.UseName = fr.UserName; }
------解决方案--------------------
可以自己重写一个Form的构造函数。参数可以是你想要传递的。
------解决方案--------------------
1.置换顺序
f.UseName = fr.UserName;
f.Show();
2.搞个全局变量
------解决方案--------------------
form1.cs
- C# code
public partial class Form1 : Form { private Form2 f; public Form1() { InitializeComponent(); f = new Form2(); } private void menuItem1_Click(object sender, EventArgs e) { f.TextToDeliver = this.textBox1.Text; f.Show(); } }