如何检测任何非 TextBox 控件上的 MouseDown?
TextBoxes 和 NumericUpDowns 有一个奇怪的属性,即一旦选择它们就不允许取消选择它们。当我的用户选择 NumericUpDown 并单击表单上的其他位置时,应取消选择 NumericUpDown。
不幸的是,事实并非如此。目前,我只是处理表单上所有其他控件(如面板和实际表单本身)的 MouseDown 事件,并调用随机标签的 Focus 方法以从 NumericUpDown 中删除焦点。但是,这不能应用于菜单项或滚动条。
必须有更好的方法来做到这一点。用户可能想要滚动面板而不是 NumericUpDown,并直观地单击面板,然后使用滚轮,但目前这会滚动 NumericUpDown,因为它仍然具有焦点。
感谢您的阅读。
编辑:问题仍未解决。
TextBoxes and NumericUpDowns have the odd property of not allowing you to deselect them once they are selected. When my user selects a NumericUpDown and clicks else-where on the form, the NumericUpDown should be deselected.
Unfortunately, this is not the case. Currently I am just handling the MouseDown event of all other controls on the form (like the panels and actual form itself) and just calling the Focus method of a random label to remove the focus from the NumericUpDown. However, this cannot be applied to menu items or scrollbars.
There must be a better way to do this. The user may want to scroll the panel instead of the NumericUpDown and intuitively click the Panel and then use the scroll-wheel, but currently that would scroll the NumericUpDown instead, since it still has focus.
Thanks for reading.
Edit: Problem still unsolved.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
通常面板控件是不可聚焦控件。因此,单击面板不会从 TextBox 或 NumericUpDown Control 中移除焦点。
解决方法可以是,在面板上放置一个按钮并将其移离视图,例如设置其 x = -100 和 y = -100。不要设置visible = false。
现在,每当用户单击面板(Panel_Click 事件)时,都会将焦点(Button.Focus())设置到该按钮。这样面板就可以通过滚轮滚动。
Normally Panel Control is a Non-Focusable control. Therefore clicking on Panel will NOT remove focus from TextBox or NumericUpDown Countrol.
The workaround can be, place a button on panel and move it away from view for example setting its x = -100 and y = -100. Do NOT set visible = false.
Now whenever user clicks on Panel (Panel_Click event) set focus (Button.Focus()) to that button. In this way panel will be scrollable through scroll-wheel.
将数字框放在某种面板中,然后
我测试它并且它有效。!
Enclose the numeric box within a panel of some sort and then do
I tested it and it works.!