码迷,mamicode.com
首页 > 其他好文 > 详细

Form页面传值问题

时间:2015-12-18 10:29:53      阅读:109      评论:0      收藏:0      [点我收藏+]

标签:

主要用到的传值方式

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 + "]";
}

  目前一般就用这些,以后再有继续补充

 

Form页面传值问题

标签:

原文地址:http://www.cnblogs.com/CurryZhang/p/5056213.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!