开发者

How to use an object in more than one form in Visual C#?

开发者 https://www.devze.com 2023-01-11 14:03 出处:网络
I\'m new in c#. I have read some book about c# for beginners. Now i can code simple applic开发者_开发百科ations. I have 2 forms and 1 class in a project. I want to use a object from that class in 2 fo

I'm new in c#. I have read some book about c# for beginners. Now i can code simple applic开发者_开发百科ations. I have 2 forms and 1 class in a project. I want to use a object from that class in 2 forms. I want first form to set a property of the object and secont to display this property. How can i do it. Please help me. Thanks


You need to change the constructor of the second form to take the class instance as a parameter.

For example:

public partial class PopupForm : Form {
    public PopupForm(MyClass instance) {
        InitializeComponent();
        //Do things with instance
    }
    ...
}
0

精彩评论

暂无评论...
验证码 换一张
取 消