Hello,
I have a class:
And I set those variables in Form1:Code:class Class1 { private string _name; public string Name { get { return _name; } set { _name = value; } } private string _lastName; public string LastName { get { return _lastName; } set { _lastName = value; } } }
So I want to access this class instance from Form2 and Form3 which is created in Form2. How can I do that?Code:public partial class Form1 : Form { Class1 myClass = new Class1(); public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { myClass.Name = "John"; myClass.LastName = "Doe"; Form2 myForm2 = new Form2(); myForm2.ShowDialog(); } }
I tried something like:
But I couldn't access it from Form2 and Form3.Code:public partial class Form1 : Form { Class1 myClass = new Class1(); public Class1 sendClass { get { return myClass; } } . . .
Thanks.


Reply With Quote
