I'm using Visual Studio to make a windows form application. I want to pass a int called loginCount from form1 to form2. So I can click a button in form2 that takes 1 from loginCount.
Asked
Active
Viewed 1,306 times
1 Answers
0
You can use Form2 constructor for it:
var form2 = new Form2(loginCount);
If you need to access your main form members, you can pass the whole Form1 pointer into Form2:
var form2 = new Form2(this); // where "this" is your Form1
class Form2
{
private readonly Form1 mainForm;
public Form2(Form1 mainForm)
{
this.mainForm = mainForm;
}
public void DoSomething()
{
var loginCount = mainForm.loginCount; // use it!
}
}

Andrei
- 42,814
- 35
- 154
- 218
-
Thank you so much! I now understand the concept. – Lucas Thornton Dec 19 '15 at 18:41
-
Wait, where would I put the code: var form2 = new Form2(loginCount); – Lucas Thornton Dec 19 '15 at 18:43
-
@LucasThornton where you create your second form. – Andrei Dec 19 '15 at 20:53