是的,在技术上是可行的。因为许多成员是私人的和内部的,所以需要进行反思。启动一个新的Windows
Forms项目并添加两个按钮。然后:
using System;using System.ComponentModel;using System.Windows.Forms;using System.Reflection;namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); button1.Click += new EventHandler(button1_Click); // Get secret click event key FieldInfo eventClick = typeof(Control).GetField("EventClick", BindingFlags.NonPublic | BindingFlags.Static); object secret = eventClick.GetValue(null); // Retrieve the click event PropertyInfo eventsProp = typeof(Component).GetProperty("Events", BindingFlags.NonPublic | BindingFlags.Instance); EventHandlerList events = (EventHandlerList)eventsProp.GetValue(button1, null); Delegate click = events[secret]; // Remove it from button1, add it to button2 events.RemoveHandler(secret, click); events = (EventHandlerList)eventsProp.GetValue(button2, null); events.AddHandler(secret, click); } void button1_Click(object sender, EventArgs e) { MessageBox.Show("Yada"); } }}
如果这使您确信Microsoft确实非常努力地阻止您执行此 *** 作,那么您就可以理解代码。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)