// 假设有 button1 和 button2 两个按钮,下面代码实现从 button1 克隆事件到 button2 // 原文:https://stackoverflow.com/questions/6055038/how-to-clone-control-event-handlers-at-run-time FieldInfo eventsField = typeof(Component).GetField("events", BindingFlags.NonPublic | BindingFlags.Instance); object eventHandlers = eventsField.GetValue(button1); eventsField.SetValue(button2, eventHandlers);
时间: 2024-10-11 05:29:12