Hello,

I don't know if such question was already posted but I didn't find anything
through different posts.

I have the Main MDI window with a StatusBar. Inside my StatusBar there is a
ProgressBar. When I click on the menu in my MDI Parent, a child form is
loaded. I would like to know if there is a way to increment a progressbar
value while child form is loading ? I tried to use background worker but i
had some cross thread access exceptions. any ideas ? Thanks in advance.

Thomas
--
Thomas JASKULA - NODEVO
1, avenue du Général de Gaulle
60500 - Chantilly

Re: ProgressBar and Form loading by Norman

Norman
Tue Jun 10 09:32:26 CDT 2008

A fairly simple way is to add event to the child form and fire it a few
times to indicate the progress when the child form is loading.

Psuedo code example:

in the child form:

public class ChildForm:Form
{
...
public event System.EventHanler LoadProgressIncrcemented;

//Assume you place all loading logic in Form_Load()
public ChildForm_Load(...)
{
//Fire first event
if (LoadProgressIncremented!=null) LoadProgressIncremented(this,new
EventArgs());

//Do some loading code here

//Fire second event
if (LoadProgressIncremented!=null) LoadProgressIncremented(this,new
EventArgs());

//Do some loading code here

//Fire third event
if (LoadProgressIncremented!=null) LoadProgressIncremented(this,new
EventArgs());

//Do some loading code here

//Fire more event by dividing the loading process into more steps,
when necessary
......
}

In the Main form, when you instantiate a child form, you can subscribe the
event and in the evenet handler procedure you can then set the progress bar:

public class MainForm:Form
{
....
private ShowChildForm()
{
ChidForm frm=new ChildForm();

//Subcribe child form's loading event
frm.LoadProgressIncremented+=new
EventHandler(ChildForm_LoadProgressInccremented)

//Reset progress bar
ProgressBar1.Value=0
ProgressBar1.Max=10; //Assume you are going to fire child form
loading event 10 times.

//Now strat loading the child form
frm.Show();
}

private void ChildForm_LoadProgressIncremented(object sender, EventArgs
e)
(
//Update progress bar
if (ProgressBar1.Value<=10) ProgressBar1.Value++;
)
}

You can derive your own child form loading event argument from
System.EventArgs to pass more detailed loading information to the main form
with event.


"Thomas" <tjaskula@nodevo.com> wrote in message
news:1C25C4B6-9180-483C-B5FE-82CCF2AE6CD9@microsoft.com...
> Hello,
>
> I don't know if such question was already posted but I didn't find
> anything through different posts.
>
> I have the Main MDI window with a StatusBar. Inside my StatusBar there is
> a ProgressBar. When I click on the menu in my MDI Parent, a child form is
> loaded. I would like to know if there is a way to increment a progressbar
> value while child form is loading ? I tried to use background worker but i
> had some cross thread access exceptions. any ideas ? Thanks in advance.
>
> Thomas
> --
> Thomas JASKULA - NODEVO
> 1, avenue du Général de Gaulle
> 60500 - Chantilly