Hi,
I have problem with control event handler. I created a control ( button ) and I want to bind click event with a method. But I have "Error binding to target method." exception.
code is,
class SetControlEvent
{
public void Sleep()
{
System.Threading.Thread.Sleep(5000);
}
internal void Set(object theObject,XmlNode theControlNode)
{
EventInfo ei = theObject.GetType().GetEvent("Click");
EventDescriptorCollection events = TypeDescriptor.GetEvents(theObject);
foreach (EventDescriptor theEvent in events)
{
foreach (XmlAttribute attribute in theControlNode.Attributes)
{
if (theEvent.DisplayName == attribute.Name)
{
MethodInfo mi = typeof(SetControlEvent).GetMethod("Sleep");
Delegate del = Delegate.CreateDelegate(ei.EventHandlerType, this, "Sleep");
theEvent.AddEventHandler(theObject, del);
break;
}
}
}
}
}
so, what should I do?
thanks...