View Single Post
Join Date: Jul 2008
Posts: 27
Reputation: nikola.rosic is an unknown quantity at this point 
Solved Threads: 0
nikola.rosic nikola.rosic is offline Offline
Light Poster

Re: openin more forms C#

 
0
  #8
Dec 3rd, 2008
Originally Posted by LizR View Post
This is the bit that worries me
  1. Form2 form1=new Form2();
  2. Form2 form2=new Form2();
  3. Form2 form3=new Form2();

if your worker makes those forms then how is it sure which form its using?
well the first background worker
this code is in main:

BackgroundWorker bw1 = new BackgroundWorker();
bw1.DoWork += new DoWorkEventHandler(BWClass1.bw1_DoWork);

this code down is in BWClass1!!!!

public static Form2 form1;

public static void bw1_DoWork(object sender, DoWorkEventArgs e)
{
form1=new Form2(0);
}

this code down is in BWClass2!!!!

the second background worker those the same but for

public static void bw2_DoWork(object sender, DoWorkEventArgs e)
{
form2=new Form2(1);
}

each background worker is using his one instance in function.

in constructor i am passing an argument Form2(1) which says which form should he draw and which form to update

i am doing the update of instance of Form2 in each backgroundworker for each form with get,set properties.For an example:

backgroundworker1:
form1.TEMP_PROFIL1 =temperature1;
form1.TEMP_PROFIL2 =temperature2;
form1.SREDNJA_TEMP = average_temp;
form1.MAKS_TEMP = max_temp;

backgroundworker2:
form2.TEMP_PROFIL1 =temperature1;
form2.TEMP_PROFIL2 =temperature2;
form2.SREDNJA_TEMP = average_temp;
form2.MAKS_TEMP = max_temp;

after i do my update I call an event which will draw an panel on specified Form2 instance


form1.clicked();

or

form2.clicked();


the function of the event is declared in Form2 class!!!

Hopes this clarifies a bit more!!!
Reply With Quote