I seem to be going no-where fast with passing a method name as a string and assigning it to a delegate.
I want to have a class that assigns a dynamic method from a parameter but can't work out how to do it.
private delegate void ProgressMsg(string msg);
private ProgressMsg AddMsg;
public Progress(string FormName, string AddMsgMethodName, bool close, bool hide)
{
// set properties
this.Hide = hide;
this.Close = close;
// Open form if not open
this.Frm = Application.OpenForms[FormName];
if (this.Frm == null)
{
// instatiate form
this.Frm = (Form)Assembly.GetExecutingAssembly().CreateInstance(Assembly.GetExecutingAssembly().GetName().Name + "." + FormName);
// show form
this.Frm.Show();
}
// assign delegate
this.AddMsg = new ProgressMsg(AddMsgMethodName);
// Hide form
this.Frm.Visible = !Hide;
}
How can I pass the name of a form, and the method to call and then assign to the delegate the method from the form?