Multy form question
-
Can someone help me with multy form communication ? The question is: If I have 2,3,more... forms visible how can form number 1 send some data (for exmaple: move progress bar) on Form number 2,3,4,more... ?? Sending varibales from one form to another,sharing resources and stuff ?? :laugh: "I have not failed. I've just found 10,000 ways that won't work." - Thomas Alva Edison (1847-1931)
-
Can someone help me with multy form communication ? The question is: If I have 2,3,more... forms visible how can form number 1 send some data (for exmaple: move progress bar) on Form number 2,3,4,more... ?? Sending varibales from one form to another,sharing resources and stuff ?? :laugh: "I have not failed. I've just found 10,000 ways that won't work." - Thomas Alva Edison (1847-1931)
There is more than one way to do this. 1/ You can have a singleton object in your system that will hold data (for example ints) through which these forms will communicate. 2/ If you have a singleton, one form could fire an event when it wishes to communicate data, the singleton have an event handler, and then invoking a method on form2 to set the variable.
-
Can someone help me with multy form communication ? The question is: If I have 2,3,more... forms visible how can form number 1 send some data (for exmaple: move progress bar) on Form number 2,3,4,more... ?? Sending varibales from one form to another,sharing resources and stuff ?? :laugh: "I have not failed. I've just found 10,000 ways that won't work." - Thomas Alva Edison (1847-1931)
-
1. Make the progress bar Public. 2. To the form number 1 give the references to forms 2,3,4... 3. Use the reference to move progress bar. The refenrences can be passed as a constructor parameter or kept as a static array.
-
Like this ?
//on Form 1 Form frm2 = new MyNamespace.Form2(); frm2.Show(); ++frm2.progressBar1.value;
This is what you mean ? "I have not failed. I've just found 10,000 ways that won't work." - Thomas Alva Edison (1847-1931) -
But in this case I have to make progressBar1 on Form2 - static !
public **static** ProgressBar progressBar1;
otherwise I can not see it :( "I have not failed. I've just found 10,000 ways that won't work." - Thomas Alva Edison (1847-1931)You can not see it because you use general type to reference your form. Consider the example:
Form frm1 = new MyFormWithProgressBar();
frm1.Show();
frm1.progressBar1.Value++; // this is errorThe correct code is:
MyFormWithProgressBar frm1 = new MyFormWithProgressBar();
frm1.Show();
frm1.progressBar1.Value++; // this will workSorry that I have not noticed that mistake in your previous post.
-
You can not see it because you use general type to reference your form. Consider the example:
Form frm1 = new MyFormWithProgressBar();
frm1.Show();
frm1.progressBar1.Value++; // this is errorThe correct code is:
MyFormWithProgressBar frm1 = new MyFormWithProgressBar();
frm1.Show();
frm1.progressBar1.Value++; // this will workSorry that I have not noticed that mistake in your previous post.