怎样在winform插入代码
如一个button, 怎样在click事件插入一个代码?
下面这段代码只能给事件加入一个空的代码段, 不知道怎样再加入代码
public static void ConnectEvent(IComponent component, string EventName)
{
if (component.Site == null)
{
MessageBox.Show("component.Site is null.");
return;
}
IEventBindingService eventservice = (IEventBindingService)component.Site.GetService(typeof(System.ComponentModel.Design.IEventBindingService));
if (eventservice == null)
{
MessageBox.Show("IEventBindingService is null.");
return;
}
EventDescriptorCollection edc = TypeDescriptor.GetEvents(component);
if (edc == null || edc.Count == 0)
{
MessageBox.Show("EventDescriptorCollection is null or empty.");
return;
}
EventDescriptor ed = null;
foreach (EventDescriptor edi in edc)
if (edi.Name == EventName)
{
ed = edi;
break;
}
if (ed == null)
{
MessageBox.Show(string.Format("Search for an event named \"{0}\" failed.", EventName));
return;
}
PropertyDescriptor pd = eventservice.GetEventProperty(ed);
if (pd == null)
{
MessageBox.Show("PropertyDescriptor is null.");
return;
}
string methodName = component.Site.Name + "_" + EventName;
if (!ValidName(component.Site, methodName))
{
methodName = NewName(component.Site, methodName);
}
pd.SetValue(component, methodName);
}
[解决办法]
没明白楼主的意思
button在click事件插入一个代码
这是按钮单击事件么?
[解决办法]
看帖就要回帖,虽然我不能帮助楼主。
[解决办法]
代码没有经过编译就无法加入,源代码和二进制码是有区别的,
[解决办法]
应该没法做到,除非你调用编译器编译源代码,
[解决办法]
没明白楼主的意思
[解决办法]