如何从另一个表单发送C#中Form_Load的参数? [英] How to send parameter for Form_Load in C# from Another Form?

查看:237
本文介绍了如何从另一个表单发送C#中Form_Load的参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从主表单向第二个表单的form_load发送一个标志.
thx.

i want to send a flag to form_load of my second form , from the main form.
thx.

推荐答案

U必须修改默认构造函数,或者可以为第二种形式定义参数化构造函数.
U have to modify the default constructor or may define a parameterized constructor for the second form.
public Form2(string flag)
        {
            //code
        }


并在调用此表单时传递参数.

您也可能会这样:
在第二个表单上定义一个公共属性.
在调用该表单之前设置属性.
像这样的东西:


And while calling this form pass the parameter.

You may also do like this:
Define a public property on your second form.
Set the property before calling that form.
Something like this:

In form 2:
public string flag
    {
        get { return _Flag; }
        set { _Flag = value; }
    }

In Main form:
Form2 myForm = new Form2();
myForm.flag = value;
myForm.Show();


希望这对您有帮助!


Hope this helps!!!


1.在form1中将标志变量声明为public static

2.在form2的表单加载中,通过"form2.flag"访问该标志.
希望对您有帮助
1. declare the flag variable as public static in form1

2. In form load of form2 access the flag by "form2.flag"

Hope this wil help you


这篇关于如何从另一个表单发送C#中Form_Load的参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆