R
Ronin
I need a little help trying to figure out the last piece of this
puzzle.
I've got a form with an associated toolbox that will allow a user to
drag a control off the toolbox and drop it onto the form. The form
instantiates the control using the Activator.CreateInstance method.
What I then need to do (and the part I have not figured out) is how to
attach a method from that control (a custom data refresh method) to a
timer.elapsed eventhandler on the form. I have been unable to figure
out how to get visibility of the method I need to attach.
Here's the code I have so far.
private void layoutPanel_DragDrop(object sender, DragEventArgs e)
{
NavBarItemLink link = GetItemLink(e.Data);
if (link != null && link.Item.Enabled)
{
String ctrlName = link.ItemName;
String className;
String methodName;
Type t = null;
MethodInfo m = null;
Assembly a = Assembly.Load("JacobsControls");
Type[] types = a.GetTypes();
foreach (Type definedType in types)
{
className = definedType.Name;
if (className == ctrlName)
{
t = definedType;
MethodInfo[] methods = t.GetMethods();
foreach (MethodInfo method in methods)
{
methodName = method.Name;
if (methodName == "RefreshControl")
{
m = method;
break;
}
}
break;
}
}
Object[] constructorArgs = { (int)13, (int)1 };
Object o = Activator.CreateInstance(t, constructorArgs);
layoutPanel.Controls.Add((Control)o);
// This is where the newly created control needs to have
// a "RefreshControl" method attached to a timer.
}
Thanks,
Jason
puzzle.
I've got a form with an associated toolbox that will allow a user to
drag a control off the toolbox and drop it onto the form. The form
instantiates the control using the Activator.CreateInstance method.
What I then need to do (and the part I have not figured out) is how to
attach a method from that control (a custom data refresh method) to a
timer.elapsed eventhandler on the form. I have been unable to figure
out how to get visibility of the method I need to attach.
Here's the code I have so far.
private void layoutPanel_DragDrop(object sender, DragEventArgs e)
{
NavBarItemLink link = GetItemLink(e.Data);
if (link != null && link.Item.Enabled)
{
String ctrlName = link.ItemName;
String className;
String methodName;
Type t = null;
MethodInfo m = null;
Assembly a = Assembly.Load("JacobsControls");
Type[] types = a.GetTypes();
foreach (Type definedType in types)
{
className = definedType.Name;
if (className == ctrlName)
{
t = definedType;
MethodInfo[] methods = t.GetMethods();
foreach (MethodInfo method in methods)
{
methodName = method.Name;
if (methodName == "RefreshControl")
{
m = method;
break;
}
}
break;
}
}
Object[] constructorArgs = { (int)13, (int)1 };
Object o = Activator.CreateInstance(t, constructorArgs);
layoutPanel.Controls.Add((Control)o);
// This is where the newly created control needs to have
// a "RefreshControl" method attached to a timer.
}
Thanks,
Jason