Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 26-11-2009
Member
 
Join Date: Jun 2009
Posts: 53
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?
Reply With Quote
  #2  
Old 26-11-2009
Member
 
Join Date: May 2008
Posts: 685
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.
Reply With Quote
  #3  
Old 26-11-2009
Member
 
Join Date: Jun 2009
Posts: 53
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.
Reply With Quote
  #4  
Old 26-11-2009
Member
 
Join Date: May 2008
Posts: 685
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 ? " );
   }
}
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "An instance of class Business works for many forms"
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


All times are GMT +5.5. The time now is 06:45 AM.