Created
March 6, 2018 15:01
-
-
Save pavelovcharov/1e53f62acfc654b65618cae5971d66f0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| EventInfo evClick = GetType().GetEvent("GotKeyboardFocus"); | |
| Type tDelegate = evClick.EventHandlerType; | |
| MethodInfo miHandler = | |
| typeof(LayoutPanel).GetMethod("Control_GotFocus", | |
| BindingFlags.NonPublic | BindingFlags.Instance); | |
| // Create an instance of the delegate. Using the overloads | |
| // of CreateDelegate that take MethodInfo is recommended. | |
| // | |
| Delegate d = Delegate.CreateDelegate(tDelegate, this, miHandler); | |
| MethodInfo addHandler = evClick.GetRemoveMethod(); | |
| Object[] addHandlerArgs = { d }; | |
| addHandler.Invoke(this, addHandlerArgs); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment