I'm new in C# and I am facing a problem. I am creating a program consisting of 2 windows and a class Business. An event on any window treatment leads to the class Business. My question is how can the 2 forms work on the same class Business?
I'm new in C# and I am facing a problem. I am creating a program consisting of 2 windows and a class Business. An event on any window treatment leads to the class Business. My question is how can the 2 forms work on the same class Business?
You have some instances of a Business class in your main form, that is available to another Form via a accessor (get/set). The accessor of a property contains the executable statements associated with getting (reading or computing) or setting (writing) the property. The accessor declarations can contain a get accessor, a set accessor, or both.
Okay, but how practically you can access from another Form? Because the class instantiated in the main form does not exist in the context of the other window, so I do not have access to its accessors.
When you call your secondary form, it assists you in setting the form that instantiated class job, and you can have access to its properties:
Code:public class Form1 { Job myJob; public Form1() { myJob = new Job(); } public Job { get { return myJob; } } private void DoWhatever() { Form2 frm = new Form2(this); myJob.Fonction1(); frm.DoWork(); } } public class Form2 { Job myJob; public Form2(Form1 form) { myJob = form.Job; } private void DoWhatever() { myJob.Fonction1(); myJob.Fonction2(); } public void DoWork() { MessageBox.Show("Kikoo lol ! asv ? " ); } }
Bookmarks