Hi
I have a small problem. I have a class that does stuff. And I have my form. Now when I press a button. My class does something. Now what I want is that I my progress bar will update. But my class cant see the progress bar. I know why but how would I fix this ???
I don't know whether you'll get a lot more from them but these are the relevant MSDN links:
http://msdn.microsoft.com/en-us/library/system.windows.forms.application.openforms.aspx
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.controls.aspx
http://msdn.microsoft.com/en-us/library/system.windows.forms.splitcontainer.aspx
aha thank you. do you know wher i can find some more info on this. (microsoft site) so that i can study it a bit more
It's probably because the two Panels are an integral part of the SplitContainer control rather than independent controls added to its Controls collection. Also they're of type SplitterPanel rather than Panel.
See if the following will work:
SplitContainer s1 = (SplitContainer)f1.Controls["splitContainer1"];
SplitterPanel p1 = s1.Panel1;
ProgressBar pb1 = (ProgressBar)p1.Controls["progressBar1"];
Label lb1 = (Label)p1.Controls["label1"];
pb1.Value = 50;
lb1.Text = "hi";
thank you for aal you help. but ui still need to ask,
why doesent this work
Form1 f1 = (Form1)Application.OpenForms["Form1"];
Panel p1 = (Panel)s1.Controls["panel1"];
To code the hypothetical example I mentioned in my previous post, you'd do something like this:
Form1 f1 = (Form1)Application.OpenForms["Form1"];Panel p1 = (Panel)f1.Controls["panel1"];TextBox tb = (TextBox)p1.Controls["textBox1"];tb.Text += "whatever";
I'm sorry to ask but how wold i do more than two steps. can you give me an example. I'm still new so i dont know all of the comon knowlege. :}
thanks
Ah ok cool thanks. well if something els comes op about this i will ask :} thank you again :}
Yes, it'll work for any control on any open form in the current application.
Sometimes, though, you need to go through more than two steps. For example if you wanted to add text to a textbox on a panel within a form, then you'd need to get references to the form, panel and textbox before using the latter's Text property to add the text.
This is because the textbox would be in the panel's Controls collection rather than the form's.
ah cool. thaks.
dows this work for every thing ???
Your class first needs a reference to your form (Form1 say) so that it can then get a reference to your ProgressBar(progressBar1 say) and update it.
If you're using .NET 2.0 or later, you can do it like this:
Form1 f1 = (Form1)Application.OpenForms["Form1"];ProgressBar pb1 = (ProgressBar)f1.Controls["progressBar1"];pb1.PerformStep();