开发者

Cannot deselect 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 NumericUp开发者_C百科Down.

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.


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.


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();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜