c# Control.Validating 事件将鼠标焦点留在其他控件上?

发布于 2024-09-28 01:10:15 字数 205 浏览 1 评论 0原文

我有带有文本框和轨迹栏的 ac# .net 2.0 winForm。如果用户单击轨迹栏并且验证失败,文本框验证事件将设置 e.cancel。然后,我将光标留在文本框中,但鼠标焦点仍然在轨迹栏上,因此移动鼠标会移动轨迹栏。

我在验证事件中尝试过 SetFocus(根据 MSDN 的说法很糟糕,但我还是尝试了),但鼠标停留在轨迹栏上。

如何将鼠标焦点从轨迹栏上分离?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

过期以后 2024-10-05 01:10:15
  • 您是否在消息框中显示验证错误消息。如果是这种情况,则不会触发鼠标释放轨迹栏,因为消息框将获得控制权,这就是您退出消息框后看到轨迹栏移动的原因。
  • MessageBox 和验证事件不能很好地配合。最好的方法是使用 ErrorProvider
  • 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.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文