views:

29

answers:

2

I have a c# .net 2.0 winForm with a textbox and a trackbar. The textbox Validating event sets e.cancel if the user clicks the trackbar and the validation fails. I am then left with the cursor in the textbox, but the mouse focus is still on the trackbar so moving the mouse moves the trackbar.

I have tried SetFocus in the validating event (bad according to MSDN but I tried anyway) but the mouse stays on the trackbar.

How do I detach the mouse focus from the trackbar?

A: 
  • Are you displaying the validation error message in a message box. If that is the case the mouse release of trackbar wouldnt have fired as the message box would have taken control and that's the reason you are seeing the trackbar moving after you exit the message box.
  • MessageBox and validating event dont go well with each other. Best way to do it is to use a ErrorProvider.
anivas
A: 

Yes was firing a messagebox :) sorted now. Thanks

BillyG