0

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.

1 Answers1

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