Results 1 to 4 of 4

Thread: An instance of class Business works for many forms

  1. #1
    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?

  2. #2
    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.

  3. #3
    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.

  4. #4
    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 ? " );
       }
    }

Similar Threads

  1. Replies: 3
    Last Post: 05-12-2011, 02:22 AM
  2. Replies: 5
    Last Post: 12-02-2010, 06:23 PM
  3. How to implement Session Beans in Business delegate class?
    By StudyBoy in forum Software Development
    Replies: 3
    Last Post: 01-04-2009, 09:35 AM
  4. AMD to release Six 45nm Business class CPUs in Q3
    By marlyn in forum Portable Devices
    Replies: 2
    Last Post: 06-01-2009, 12:08 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,965,082.15514 seconds with 16 queries