code_junkie

LIghtweight instrumentation

Nov 12th, 2011
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. // execute this method once all forms have been created
  2. public static void HookButtons()
  3. {
  4. foreach( Form f in Application.OpenForms )
  5. {
  6. EnumerateControls( f.Controls );
  7. }
  8. }
  9.  
  10. public static void EnumerateControls( ICollection controls )
  11. {
  12. foreach( Control ctrl in controls )
  13. {
  14. if( ctrl.Controls.Count > 0 )
  15. {
  16. EnumerateControls( ctrl.Controls );
  17. }
  18.  
  19. if( ctrl is ButtonBase )
  20. {
  21. ctrl.MouseClick +=new MouseEventHandler( ctrl_MouseClick );
  22. }
  23. }
  24.  
  25. }
  26.  
  27. static void ctrl_MouseClick( object sender, MouseEventArgs e )
  28. {
  29. ButtonBase clicked = ((ButtonBase)sender);
  30.  
  31. // do something with the click information here
  32. }
Add Comment
Please, Sign In to add comment