c# Form

Oct 7 2008 9:23 AM

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 ???


Answers (11)

1
danie van ophem

danie van ophem

  • 0
  • 13
  • 0
Oct 8 2008 3:10 PM
Ah cool Thank you so much for all your help :}
1
danie van ophem

danie van ophem

  • 0
  • 13
  • 0
Oct 8 2008 1:56 PM

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

 

1
Alan

Alan

  • 0
  • 5.8k
  • 0
Oct 8 2008 1:52 PM

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";

1
danie van ophem

danie van ophem

  • 0
  • 13
  • 0
Oct 8 2008 12:20 PM

thank you for aal you help. but ui still need to ask,

why doesent this work

Form1 f1 = (Form1)Application.OpenForms["Form1"];

SplitContainer s1 = (SplitContainer)f1.Controls["splitContainer1"];

Panel p1 = (Panel)s1.Controls["panel1"];

ProgressBar pb1 = (ProgressBar)p1.Controls["progressBar1"];

Label lb1 = (Label)p1.Controls["label1"];

pb1.Value = 50;

lb1.Text = "hi";

 

1
Alan

Alan

  • 0
  • 5.8k
  • 0
Oct 7 2008 3:19 PM

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";

1
danie van ophem

danie van ophem

  • 0
  • 13
  • 0
Oct 7 2008 2:54 PM

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

1
danie van ophem

danie van ophem

  • 0
  • 13
  • 0
Oct 7 2008 12:15 PM

Ah ok cool thanks. well if something els comes op about this i will ask :} thank you again :}

1
Alan

Alan

  • 0
  • 5.8k
  • 0
Oct 7 2008 12:10 PM

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.

1
danie van ophem

danie van ophem

  • 0
  • 13
  • 0
Oct 7 2008 12:01 PM

ah cool. thaks.

dows this work for every thing ???

1
Alan

Alan

  • 0
  • 5.8k
  • 0
Oct 7 2008 9:51 AM

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();