你在form2中是重新定义一个form1,当然不行了,你把新定义的form1显示出来就会看到已经赋值成功了! private void button1_Click(object sender, EventArgs e)
{
Form1 f = new Form1();
f.t = this.textBox1 .Text ;
f.show();
}
{
Form1 f = new Form1();
f.t = this.textBox1 .Text ;
f.show();
}
解决方案 »
- 查询数据的时候窗体出现假死
- Form.show和另一线程下的form.showdialog有何异同,顺便散分,周末结贴
- 不知道各位坛友有制作QQ的素材吗?
- SourceGear Vault怎么用的?
- 关于一个以table 形式返回的函数问题?
- 谢谢,请救:webBrowser 如何得到其文本中的光标位置??
- 以释放所有代码路径的类型为“'conn'”的本地 SqlConnection
- 水晶报表crystalreport问题,我得数据填充无效。
- 为何从旧文件夹移动 文件到新文件夹时报错
- 不知道这句SQL语句在ADO中能不能被执行Exec sp_addlogin 'user1','user1'
- 怎样用C#开发一个 显示微博内容的 自定义控件
- 摄像头实时显示影像变形..标题要长.............才会醒目........
private void button1_Click(object sender, EventArgs e)
{
Form2 fm = new Form2(this);//定义fm的时候,要把form1对象传递过去
fm.Show();
}
public string t
{
get { return this.textBox1.Text; }
set { this.textBox1.Text = value; }
}
form2中代码:
//增加定义一个变量保存form1
private Form1 frm1;
//修改构造函数
public Form2(Form1 frm)
{
this.frm1=frm;
}
private void button1_Click(object sender, EventArgs e)
{
//对传递过来的from1对象进行修改
this.frm1.t=this.textBox1 .Text ;
}
{
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();
}
}
或
public string t
{
get { return this.textBox1.Text; }
set { this.textBox1.Text = value; }
}
frm1.t=this.textBox2.Text;
Form2 f = new Form2();
private void button1_Click(object sender, EventArgs e)
{
f.getvalue += new Form2.getvalueHandler(f_getvalue);
f.Show();
}
string f_getvalue()
{
return textBox1.Text;
}
-----------------form2 代码-----------------------------------------
public delegate string getvalueHandler();
public event getvalueHandler getvalue; private void Form2_Load(object sender, EventArgs e)
{
textBox1.Text = getvalue();
}