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

后端 未结 5 511
我寻月下人不归
我寻月下人不归 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:52

    PRO TIP

    In the future, think about it in a more generic way: a Form is just a class, and the Load event is just a method.

    If you were trying to pass a value between 2 objects that weren't Forms, you would have a public property in one class that other objects could access. This is at the heart of rsbarro's answer, and what I like to call "Forms are classes too" :)

提交回复
热议问题