views:

172

answers:

3

what is the best way to capture user clicks in my winform application with out making the code very complicated. is AOP the answer ? any good links or examples of this to track instrumentations . .

A: 

The general method for capturing clicks in winforms is handling Control.MouseClick. You can also look at Control.MouseDown and Control.MouseUp if you want more detailed information.

If you provide more details about what you're trying to do, we can probably come up with a more targeted answer.

Charlie
A: 

Check this answer for a similar question on Winform Instrumentation for few options

Abhijit
+3  A: 

This does depend rather on your actual requirements.

For a simple/sample/prototype winforms app, I'd suggest basic WinForms Event Handlers, with the code (providing it's not too heavy) in the handler methods. If code is heavy, contains hard business rules and doesn't interact with the form then it's best to move that code to another class and call it from the event handler.

Aspect Oriented Programming takes this futher. It's generally best applied in larger-scale projects. You still need event handlers for your form elements (and I recommend sticking to the control-based event handlers - don't try creating your own global event handling facility), but they should make calls to Command objects (see Command Pattern in GangOfFour). Those command objects can then be invoked from anywhere in your application. If you want instrumentation, the instrumentation should be on those Command objects rather than the WinForms events. You can leverage Inversion of Control containers like Castle Windsor to inject logging/auditing into the commands without having to change your application at all using the Interceptor pattern. Here's an example from David Hayden

Neil Barnwell