简体   繁体   中英

c# Control.Validating event leaves mouse focus on other controls?

I have ac# .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?

  • 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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM