无法取消选择 NumericUpDown?

发布于 2024-12-01 00:26:00 字数 309 浏览 0 评论 0原文

如果您创建一个新的 C# 项目并将 NumericUpDown 放在表单(甚至是文本框)上,是否无法取消选择?

目前,我的应用程序有一个可滚动容器,当用户选择 NumericUpDown 时,他或她无法取消选择它。然后,当尝试使用鼠标上的滚轮进行任何操作时,它会滚动 NumericUpDown 的值。

理想情况下,当用户单击表单上的空白点时,它将选择该表单并取消选择 NumericUpDown。或者一般禁用 NumericUpDown 上的鼠标滚轮滚动(也不知道如何执行此操作)。 NumericUpDown 包含不会经常更改的数据,因此它根本不会对用户产生太大影响。

If you make a new C# project and place a NumericUpDown on the form (or even a textbox for that matter) is it impossible to deselect?

Currently my application has a scrollable container and when a user selects a NumericUpDown he or she cannot deselect it. Then when trying to use the scrollwheel on the mouse for anything, it scrolls the value of the NumericUpDown.

Ideally, when the user clicked in a blank spot on the form it would select the form and deselect the NumericUpDown. Either that or disable mouse-wheel scrolling on the NumericUpDown in general (not sure how to do this either). The NumericUpDown's contain data that is not bound to change often, so it would not really impact the user by that much at all.

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

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

发布评论

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

评论(2

摇划花蜜的午后 2024-12-08 00:26:00

要禁用 NumericUpDown 上的鼠标滚轮滚动,您需要创建自己的后代控件来重写 OnMouseWheel 事件,并在表单上使用自定义控件。

public class NonScrollingNumericUpDown : NumericUpDown
{
    protected override void OnMouseWheel(MouseEventArgs e)
    {
           //Don't call base.OnMouseWheel(e)
    }
}

要回答您有关控制焦点的问题,我相信您还需要在表单上至少有一个其他控件来移交焦点。

To disable the mouse wheel scrolling on a NumericUpDown you'd need to create your own descendant control that overrides the OnMouseWheel event, and use the custom control on your form.

public class NonScrollingNumericUpDown : NumericUpDown
{
    protected override void OnMouseWheel(MouseEventArgs e)
    {
           //Don't call base.OnMouseWheel(e)
    }
}

To answer your question about control Focus, I believe you would need to have at least one other control on the form to hand off the Focus too.

想你只要分分秒秒 2024-12-08 00:26:00

将标签添加到表单并清除其 Text 属性。这将为您留下一个看不到但仍可以获得焦点的标签。

在表单的 Click 事件中,调用以下代码将焦点设置到标签:

label1.Focus();

Add a Label to your form and clear its Text property. This will leave you with a Label that can't be seen but can still receive focus.

On your form's Click event, call this code to set the focus to the Label:

label1.Focus();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文