窗体之间的参数传递

1)Form1中添加两个button和一个textbox
2)在Form1中添加一个字段属性。
public string msg
{
   
get { return textBox1.Text; }
}
3)在Form2中添加一个label
4)在Form2中添加一个属性
public string msg
{
   
get{return label1.Text;}
   
set{label1.Text=value;}
}

5)重载Form2的构造函数
public Form2(Form1 f1)
{
   InitializeComponent();
   label1.Text
=f1.msg;
}

6)在Form1中调用Form2
Form2 f2 ;
private void button1_Click(object sender, EventArgs e)
{
   f2 
= new Form2(this);
   f2.Show();
}

7)实时更改Form2的参数
private void button2_Click(object sender, EventArgs e)
{
     f2.Msg 
= textBox1.Text;
}

8)完成。
posted @ 2009-08-05 10:46  盈不足  阅读(221)  评论(0编辑  收藏  举报