2)在Form1中添加一个字段属性。
public
string
msg
{
get { return textBox1.Text; }
}
3)在Form2中添加一个label
{
get { return textBox1.Text; }
}
4)在Form2中添加一个属性
public
string
msg
{
get { return label1.Text;}
set {label1.Text = value;}
}
{
get { return label1.Text;}
set {label1.Text = value;}
}
5)重载Form2的构造函数
public
Form2(Form1 f1)
{
InitializeComponent();
label1.Text = f1.msg;
}
{
InitializeComponent();
label1.Text = f1.msg;
}
6)在Form1中调用Form2
Form2 f2 ;
private void button1_Click( object sender, EventArgs e)
{
f2 = new Form2( this );
f2.Show();
}
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;
}
{
f2.Msg = textBox1.Text;
}
8)完成。