How to access control in child form (MDI app)

  • Thread starter Thread starter Karl
  • Start date Start date
K

Karl

Hi,

I'm just writing my first real c# application and I have a problem
when trying to access a control in a child form.

I am using an MDI application with a parent form called frmMain. In
this code I need to parse some files whose filenames are in an
arraylist. Since this parsing may take some time, I want to display a
child form named frmProgress (created as frmProgessBar) that will show
a ProgressBar and update it during processing.


In frmMain I have code that looks like this:

frmProgress frmProgressBar = new frmProgress ();
frmProgressBar.MdiParent = this;
frmProgressBar.Show ();

// need to set progressbar maximum and minimum here

foreach (string s in FilesArray)
{
// do processing of files here
// update progressbar value on each iteration.
}


Now, my question is: how can I access the actual ProgressBar control
in the child? (i.e. provide the code for the comments above). I can
access the child form methods such as Show but I don't know how I can
access the control methods so that I can set the maximum, minimum and
value of the ProgressBar control.

Can I somehow use frmProgressBar.Controls to access the ProgessBar or
is there a way to reference it using the progressbar name?

Thanks

Karl
 
Hi Karl,

One way to do it is to write a public method in your frmProgress that will
increase or decrease the value of the bar.
That way you can access that method in your foreach loop like:

foreach (string s in FilesArray)
{
// do processing of files here
frmProgressBar.YourMethodHere();
}

Cheers,
Christiaan
 
Back
Top