我如何使用在另一个Windows窗体应用C#中声明的变量

我如何使用在另一个Windows窗体应用C#中声明的变量

问题描述:

我想制作一个菜单,我可以在获得某个xp后解锁按钮,但是我无法从另一个表单重新获得xp的值,所以我该怎么做?



我尝试了什么:



i尝试过:public int xp {get; set;};

但是在我键入的另一种形式:totalxp = form2.xp我得到一个错误

i want to make a menu where i can unlock buttons after gaining a certain xp , but i am unable to regain access to the value of xp from another form , so what should i do ?

What I have tried:

i have tried : public int xp{get;set;};
but in the other form when i type : totalxp=form2.xp i get an error

在表单中添加一个属性你想要访问的变量;



public int n {get;组; } // n是一个非常糟糕的变量名。



然后用



访问变量theformsname.n = thevaluetosetitto;
Add a property to the form with the variable you wish to access;

public int n { get; set; } // n is a very bad name for a variable.

Then access the variable with

theformsname.n = thevaluetosetitto;