// Function to get the parent form public Form setUpParentForm() { Form _parentForm = null; // if (_parentForm != null) return; // do nothing if it is set System.ComponentModel.Design.IDesignerHost host; if (Site != null) { host = Site.GetService(typeof(System.ComponentModel.Design.IDesignerHost)) as System.ComponentModel.Design.IDesignerHost; MessageBox.Show(host.ToString()); object obj = host.GetService(typeof(Assembly)) as Assembly; if (obj != null) { } if (host != null) { if (host.RootComponent is Form) { _parentForm = (Form)host.RootComponent; MessageBox.Show("Host RootComponent ClassName: " + host.RootComponentClassName); } } } return _parentForm; } // Function to get the control events list public static List<delegate> GetEventHandlerList(Form HostForm) { List<delegate> delegates = new List<delegate>(); foreach (Control c in HostForm.Controls) { MessageBox.Show(c.Name.ToString()); EventHandlerList events = (EventHandlerList)typeof(Component) .GetField("events", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.GetField | BindingFlags.Public) .GetValue(c); object current = events.GetType() .GetFields(BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.GetField | BindingFlags.Public)[0] .GetValue(events); // MessageBox.Show("Current : " + current.ToString()); while (current != null) { delegates.Add((Delegate)GetField(current, "handler")); current = GetField(current, "next"); } } foreach (Delegate di in delegates) { MessageBox.Show(di.Method.ToString()); } return delegates; } public static object GetField(object listItem, string fieldName) { return listItem.GetType() .GetField(fieldName, BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.GetField) .GetValue(listItem); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)