更新时间:2023-11-30 20:23:10
您可以定义要在Form2中返回并在Form1中访问它们的公共变量:
You can define public variables which want to return in Form2 and access them in Form1:
public partial class Form2: Form
{
public int x; //can be private too
public string y; //can be private too
public Form2 (string file)
{
InitializeComponent();
}
//define some function which changes defined global values
}
在Form1中:
Form2 form2 = new Form2("bla bla");
form2.ShowDialog();
MessageBox.Show(form2.x.ToString());
MessageBox.Show(form2.y);