Skip to content

Instantly share code, notes, and snippets.

@pavelovcharov
Created March 6, 2018 15:01
Show Gist options
  • Save pavelovcharov/1e53f62acfc654b65618cae5971d66f0 to your computer and use it in GitHub Desktop.
Save pavelovcharov/1e53f62acfc654b65618cae5971d66f0 to your computer and use it in GitHub Desktop.
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