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