|
|
![]() |
| Thread Tools | Search this Thread |
#1
| |||
| |||
An instance of class Business works for many forms 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? |
#2
| |||
| |||
Re: An instance of class Business works for many forms 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. |
#3
| |||
| |||
Re: An instance of class Business works for many forms 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. |
#4
| |||
| |||
Re: An instance of class Business works for many forms 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 ? " ); } } |
![]() |
|
Tags: class object, csharp, form, instance |
Thread Tools | Search this Thread |
|
![]() | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
unable to sync business contacts in Business contact manager with Windows Mobile 5 in MIcrosoft outlook 2010. | Shinu | Windows Software | 3 | 05-12-2011 02:22 AM |
How to initialize a derived class with an instance of the base class in c#? | KAIRU26 | Software Development | 5 | 12-02-2010 06:23 PM |
How to implement Session Beans in Business delegate class? | StudyBoy | Software Development | 3 | 01-04-2009 09:35 AM |
AMD to release Six 45nm Business class CPUs in Q3 | marlyn | Portable Devices | 2 | 06-01-2009 12:08 PM |