C# Access Method of Form1 on Form2

后端 未结 4 943
生来不讨喜
生来不讨喜 2021-01-16 21:42

I have 2 Forms in my project. Form1 is the main Form. There I have a button to open Form2, a ListView and a method to call a url and feed the ListView with data it gets from

4条回答
  •  伪装坚强ぢ
    2021-01-16 21:58

    It creates a new instance because you are calling new.

    You can loop over Application.OpenForms and check form names. After finding Form1, you can easily call its public method;

    Form1(Application.OpenForms[0] as Form1).method();
    

提交回复
热议问题