How to use a variable of Form2 in Form1, WinForms C#?

后端 未结 2 446
醉酒成梦
醉酒成梦 2021-01-28 11:24

I have a solution in Visual Studio 2013 which contains two Forms. I want when a button pressing in Form2, the variable flag_fb is updated and I use its value in For

2条回答
  •  梦谈多话
    2021-01-28 11:42

    Something like this should also work.

    // Open form2 from form1
    using (Form2 form2 = new Form2())          
    {
     if (form2.ShowDialog() == DialogResult.OK)
     {
    
       m_myVal = form2.flag_fb;
    
     }
    
    }
    

    You should make sure flag_fb is public member variable of Form2, and also make sure it is set to desired value when user clicks OK for instance.

提交回复
热议问题