C#WinForms numericUpDown控件(删除旋转框) [英] C# WinForms numericUpDown control (removing the spin box)

查看:46
本文介绍了C#WinForms numericUpDown控件(删除旋转框)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

经过大量的谷歌搜索,我什么都没想..

After a ton of googling, I couldn't come up with anything..

有没有办法获取没有旋转框的numericUpDown控件?

Is there any way to get a numericUpDown control that does not have the spin box?

我需要一个仅接受整数的文本框,而numericUpDown具有我想要的完美行为.但是,我需要隐藏数字旋转框以限制空间.

I need a textbox that only accepts integers, and a numericUpDown has the perfect behavior that I am looking for. However, I need to hide the numeric spinbox for space constraints.

当我尝试执行诸如numericUpDown.Controls [0] .Hide()或numericUpDown.Controls.RemoveAt(0)之类的操作时,旋转框消失了,但留下了以前无法使用的空白.因此,数字在该位置滚动,这意味着浪费了空间.

When I try to do something like numericUpDown.Controls[0].Hide() or numericUpDown.Controls.RemoveAt(0), the spinbox disappears but leaves an unusuable void where the spinbox used to be. Thus the numbers scroll at that point, meaning the space is wasted..

还有其他解决方法吗?

谢谢..

推荐答案

您可以从NumericUpDown继承.诀窍是在创建控件时隐藏控件.

You can inherit from NumericUpDown. The trick is to hide control when the control is created.

public class NumericUpDownWitoutButtons : NumericUpDown
{
    public NumericUpDownWitoutButtons()
    {
        Controls[0].Visible = false;
    }

    protected override void OnPaint(PaintEventArgs e)
    {
        e.Graphics.Clear(SystemColors.Window);
        base.OnPaint(e);
    }
}

如果该按钮所在的地方看起来很怪异,也可以覆盖OnPaint.

If the place were buttons should be looks weird, override OnPaint too.

此外,您可能不需要NumericUpDown.是否足以验证只能键入数字?"C#仅数字"文本框

Also, you probably don't need NumericUpDown. Would it be enough to validate that only digits can by typed in? C# Numbers Only Textbox

这篇关于C#WinForms numericUpDown控件(删除旋转框)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆