Hi, another approach would be to use an event in your frmMain form which frmProgress subscribes to. You fire the event with the progress information (integer) and that information can be picked up by an event handler in frmProgress which can in turn update the ProgressBar control.
In your main form declare a delegate and event globally like this:
public delegate void UpdateProgress(int progress);
public event UpdateProgress OnUpdateProgress;
And when you open frmProgress, set the forms Owner property to the frmMain form instance (this is so that you can subscribe to the event from frmProgress:
frmProgress fp = new frmProgress();
fp.Owner = this;
fp.Show();
In frmProgress's load event, subscribe to the event like:
if (this.Owner is frmMain)
(this.Owner as frmMain).OnUpdateProgress += new WindowsApplication1.frmMai
When you type "+=" the IDE will detect that your trying to subscribe to an event, just press the TAB key twice and it'll fill in the remaining text (after the +=) and also create an event handler for you. In the event handler update your progress bar with the event handlers parameter. Ultimately your event handler should look something like:
private void frmProgress_OnUpdateProgre
{
this.progressBar1.Value = progress;
}
Finally, all thats left is to fire the event in frmMain, to do that just call the event with the integer that represents the progress:
OnUpdateProgress(intProgre
(remember to open frmProgress as mentioned further above... do that just before you start firing the OnUpdateProgress event... i.e. before your iteration that populates the ListView).
Main Topics
Browse All Topics





by: kprestagePosted on 2007-02-16 at 10:09:52ID: 18550487
You need to create a public member on your progress form.
MaxValue, "Message you want to display");
Something like
public void progress(int value, int max, string msg){
//code to set the progress bar.
}
Then on your main form, you will want to instantiate the progress form.
frmProgress frm = new frmProgress();
during your loop, you will want to do something like this...
frm.progress(currentValue,