开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜