How to pass string value from one form to another form's load event in C #

后端 未结 5 498
我寻月下人不归
我寻月下人不归 2020-12-03 15:12

I need to pass a string value from Form1:

public void button1_Click(object sender, EventArgs e)
{
    string DepartmentName = \"IT\";
    Form2          


        
5条回答
  •  情深已故
    2020-12-03 15:43

    You don't do it that way. Instead you can pass your string value on the constructor:

    public class Form2 
    {
        public Form2(string myParameter) : this()
        {
            //do whatever you need to do with myParameter
        }
    }
    

    the other answerers have also told you how to do it with a public property.

提交回复
热议问题