0
我在asp.net这种方法克隆我的控制:复制事件要克隆Contorl
public static Control Clone(Control ctrlSource)
{
Type t = ctrlSource.GetType();
Control ctrlDest = (Control)t.InvokeMember("" , BindingFlags.CreateInstance , null , null , null);
foreach(PropertyInfo prop in t.GetProperties())
{
if(prop.CanWrite)
{
if(prop.Name == "ID")
{
ctrlDest.ID = ctrlSource.ID + "cloned" + Security.Cryptography.Cryptography.generateRandomPrivateKey(5);
}
else
{
prop.SetValue(ctrlDest , prop.GetValue(ctrlSource , null) , null);
}
}
}
return ctrlDest;
}
如何设置目的地控制源控件事件(如Click事件)?
我有一个按钮,我想在两个面板中显示它。和我添加事件按钮。有了这段代码,我可以克隆它,但没有事件 – Raika 2011-02-17 12:53:44