如何使,将工作在多个表单变量? [英] How to make a variable that will work on multiple forms?
本文介绍了如何使,将工作在多个表单变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
现在我有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;
}
}
这篇关于如何使,将工作在多个表单变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文