How to get the value of one form in another form in WinForm

For example, we define two forms, Form1 and Form2, how to get a value in Form1 in Form2?

Solution:

  We can define a static variable in the class MyClass of Form2, for example public static string a = " ";

  Then assign a value to this static variable, for example a = lblname.text;

  Since the scope of static variables can cross classes, in the method of Form1, we can directly use the class MyClas of Form2 to call the static variable a of Form2

  MyClass.a;

  This completes the WinForm to obtain the value in another form from one form;

 

  Please correct any mistakes!

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325340237&siteId=291194637