المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Making a generic progress form



C# Programming
03-09-2011, 07:10 PM
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 typing callingControl. because it doesn't know of what type callingControl is.

Could anyone please provide some help or hints?