C# - How to make two forms reference each other

前端 未结 6 1582
忘了有多久
忘了有多久 2020-11-29 12:16

I\'m writing a WindowsForms application in MS Visual C#, and I need two forms to be able to reference each other. As I test, I created two buttons on Form1 -- one button tha

6条回答
  •  执笔经年
    2020-11-29 12:59

    When you create an instance of Form2 on the frm1 object, this new instance creates another Form1 instance, that creates a new Form 2 instance, that...

    Do you see the infinite loop?

    Create one instance of each other on the main class or as global application variables. Or pass them as parameter to each other. The .NET framework will just reference them without alocating new memory space.

提交回复
热议问题