标签:
主要用到的传值方式
1.设置全局变量
2.窗体构造函数
3.Delegate委托
第1种是只需要将所需要传值的字段或类改为Static即可
第2个方法是Form1往Form2中传值
Form1中代码
private void button_Click(object sender, System.EventArgs e)
{
Form2 f= new Form2( ”Curry“ );
f.Show();
}
Form2中代码
public Form2( string str )
{
InitializeComponent();
label.Text = str;
}
第四种主要是Form2页面往Form1页面传值
Form2页面代码
public delegate void returnValue(string str);
public returnValue Value;
private void button_Click(object sender, EventArgs e)
{
foreach (Control ctl in this.Controls)
{
if (ctl is RadioButton)
{
if (((RadioButton)ctl).Checked == true)
{
Value(ctl.Text);
}
}
}
}
Form1中代码如下
private void Form1_Load(object sender, EventArgs e)
{
Form2 f = new Form2();
f.Value = new Form2.returnValue(showBPValue);
f.Show();
}
private void showBPValue(string str)
{
Label1.Text = "[" + str + "]";
}
目前一般就用这些,以后再有继续补充
标签:
原文地址:http://www.cnblogs.com/CurryZhang/p/5056213.html