Is it possible to Click a label control on WPF/WinForm App using Microsoft Automation UI

My hint is to use Button. It derives from ICommandSource interface and therefore you can effortlessly use Command to associate Button with handler. Ask yourself: what functionality does a Label provide that a Button does not? Better look? Override default Button's Template and you will get equivalent look. As long as you do not take advantage of any additional functionality of Label I see no point is messing around with it.


You got 3 options to solve this problem from my point of view:

  1. UI Automation approach is to override the AutomationPeer of your component and return a ButtonAutomationPeer in your case. The big advantage here is beeing able to model every custom behaviour required. Microsoft's docu for further reading
  2. Use the ClickablePoint of your Label, and combine it with User32.dll (to fire the actual mouseclick on the provided coordinates). - see also microsoft mouse_event function docu for further details - This solution does not require any changes in your app but faces the following drawback: you won't be able to automate several apps simultaneously, if you don't build proper sub-routines on your own and you have to take care to keep the Application in the foreground (you may use the ShowWindow function from User32.dll for that).
  3. As already suggested by Maximus use a Button and make it look like a Label. I agree with him, that it should be a valid workaround in our case.