现在我有2种形式。我想提出一个变量(像INT),将2种形式之间传递。举例来说,我做的code第一次表单变量:公共静态INT敏= 50;
但如何我传递的变量,形成2?
Right now I have 2 forms. I would like to make a variable (Like a int) that will pass between the 2 forms. For instance, I make a variable on the first form with the code: public static int myInt = 50;
But how to I transfer that variable to form 2?
在你的第一种形式,你应该(假设你正在使用设计)
In your first form you should have (Assuming you're using the designer)
//Form1.cs
namespace myProject
{
public partial class Form1 : Form
{
public static int myInt = 50;
public Form1()
{
InitializeComponent();
}
}
}
要访问你的第二个形式,假设它们都在同一个命名空间中,使用:
To access in your second form, assuming they are in the same namespace, use:
//Form2.cs
namespace myProject
{
public partial class Form2 : Form
{
int thisInt;
public Form2()
{
InitializeComponent();
thisInt = Form1.myInt;
}
}