Making a generic progress form
-
Hi I created a form that acts as a progress indicator, including a progressbar and some labels etc. In the constructor of the progress form I register the delegate on the form that calls the progress form like so:
public ProgressForm()
{
SomeUserControl._updateProgressbarDelegate =
new SomeUserControl.UpdateProgressbarDelegate(this.UpdateProgress);
}This approach however needs to be made more generic so that it can be called from various other UserControls and forms. I`m not sure what the best aproach would be to do this. I tried passing the calling form/usercontrol through to the constructor when creating an instance of the progress form, but how would I then know that
updateProgressbarDelegate
is actually a delegate in the form/usercontrol I just passed through? If I do something like this:public ProgressForm(UserControl callingControl)
{
//do something with callingControl
}..then
updateProgressbarDelegate
will obviously not show up in intellisense when typingcallingControl.
because it doesn't know of what typecallingControl
is. Could anyone please provide some help or hints? -
Hi I created a form that acts as a progress indicator, including a progressbar and some labels etc. In the constructor of the progress form I register the delegate on the form that calls the progress form like so:
public ProgressForm()
{
SomeUserControl._updateProgressbarDelegate =
new SomeUserControl.UpdateProgressbarDelegate(this.UpdateProgress);
}This approach however needs to be made more generic so that it can be called from various other UserControls and forms. I`m not sure what the best aproach would be to do this. I tried passing the calling form/usercontrol through to the constructor when creating an instance of the progress form, but how would I then know that
updateProgressbarDelegate
is actually a delegate in the form/usercontrol I just passed through? If I do something like this:public ProgressForm(UserControl callingControl)
{
//do something with callingControl
}..then
updateProgressbarDelegate
will obviously not show up in intellisense when typingcallingControl.
because it doesn't know of what typecallingControl
is. Could anyone please provide some help or hints?Hi, there are many solutions too this problem. In your situation I would ask the question why a delegate is needed at all. As I can see you have a
UpdateProgress
method in your form. Lets assume it is public, then a caller could do the following:ProgressForm pf = new ProgressForm();
pf.Show();
for (int i = 0; i < 10000; i++)
{
//do some work
pf.UpdateProgress(i);
}To seperate the worker and the form you could introduce an interface along with a factory but I think this would go a bit to far for a forum answer :). Also browse through atricle on this site related to your needs: http://www.codeproject.com/info/search.aspx?artkw=progress[^] Robert
-
Hi I created a form that acts as a progress indicator, including a progressbar and some labels etc. In the constructor of the progress form I register the delegate on the form that calls the progress form like so:
public ProgressForm()
{
SomeUserControl._updateProgressbarDelegate =
new SomeUserControl.UpdateProgressbarDelegate(this.UpdateProgress);
}This approach however needs to be made more generic so that it can be called from various other UserControls and forms. I`m not sure what the best aproach would be to do this. I tried passing the calling form/usercontrol through to the constructor when creating an instance of the progress form, but how would I then know that
updateProgressbarDelegate
is actually a delegate in the form/usercontrol I just passed through? If I do something like this:public ProgressForm(UserControl callingControl)
{
//do something with callingControl
}..then
updateProgressbarDelegate
will obviously not show up in intellisense when typingcallingControl.
because it doesn't know of what typecallingControl
is. Could anyone please provide some help or hints? -
Hi I created a form that acts as a progress indicator, including a progressbar and some labels etc. In the constructor of the progress form I register the delegate on the form that calls the progress form like so:
public ProgressForm()
{
SomeUserControl._updateProgressbarDelegate =
new SomeUserControl.UpdateProgressbarDelegate(this.UpdateProgress);
}This approach however needs to be made more generic so that it can be called from various other UserControls and forms. I`m not sure what the best aproach would be to do this. I tried passing the calling form/usercontrol through to the constructor when creating an instance of the progress form, but how would I then know that
updateProgressbarDelegate
is actually a delegate in the form/usercontrol I just passed through? If I do something like this:public ProgressForm(UserControl callingControl)
{
//do something with callingControl
}..then
updateProgressbarDelegate
will obviously not show up in intellisense when typingcallingControl.
because it doesn't know of what typecallingControl
is. Could anyone please provide some help or hints? -
Thanks for all the replies :) I managed to sort it out