Hi. I'm new in c#. I have read some book about c# for beginners. Now i can code simple applications. 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
+3
A:
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
}
...
}
SLaks
2010-08-16 13:49:55
Thanks for your answer. But i coldnt write code for constructor. Can you write code for me please?
Togrul Ceferli
2010-08-16 13:59:45
@togrul94, what is the problem that you're having? The general syntax for a constructor is `public ClassName(ParamClass var1, ParamClass2 var2){ ..code.. }`. So in your example, it might be `public MyForm2(MyClass var1){ ..do something.. }`.
dsolimano
2010-08-16 14:06:36
OK. i understood. Thank you very much :)
Togrul Ceferli
2010-08-16 14:35:17