Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/261.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# WinForm NumericUpDown控件中的可变增量步长取决于是否按下Shift/Ctrl/etc_C#_Winforms_Visual Studio 2010_.net 4.0_Numericupdown - Fatal编程技术网

C# WinForm NumericUpDown控件中的可变增量步长取决于是否按下Shift/Ctrl/etc

C# WinForm NumericUpDown控件中的可变增量步长取决于是否按下Shift/Ctrl/etc,c#,winforms,visual-studio-2010,.net-4.0,numericupdown,C#,Winforms,Visual Studio 2010,.net 4.0,Numericupdown,我想要的是类似于VisualStudio中WinForm设计器中发生的事情,比如VS2010。如果我放置一个按钮并选择它并使用箭头键,它将在我按右键选择的任何方向上移动5个像素。现在,如果我在按住Shift键或Ctrl键的同时忘记了是哪一个,对不起,那么按钮一次只能移动1个像素 我希望我的NumericUpDown控件在C WinForm应用程序中发生这种情况。假设默认增量为100.0,较小的增量为10.0。如果可能,更小的增量可以是1.0。我该怎么做有什么提示吗 希望我不需要单独问这个问题:我

我想要的是类似于VisualStudio中WinForm设计器中发生的事情,比如VS2010。如果我放置一个按钮并选择它并使用箭头键,它将在我按右键选择的任何方向上移动5个像素。现在,如果我在按住Shift键或Ctrl键的同时忘记了是哪一个,对不起,那么按钮一次只能移动1个像素

我希望我的NumericUpDown控件在C WinForm应用程序中发生这种情况。假设默认增量为100.0,较小的增量为10.0。如果可能,更小的增量可以是1.0。我该怎么做有什么提示吗


希望我不需要单独问这个问题:我也在考虑让增量依赖于输入的当前值。比如说,我可以输入1到1000亿美元的金额。然后,我希望默认、较小和较小的增量值取决于输入的值。我可以自己算出确切的公式。

从NumericUpDown派生您自己的类,并重写UpButton和DownButton方法:

using System;
using System.Windows.Forms;

public class MyUpDown : NumericUpDown {
    public override void UpButton() {
        decimal inc = this.Increment;
        if ((Control.ModifierKeys & Keys.Control) == Keys.Control) this.Increment *= 10;
        base.UpButton();
        this.Increment = inc;
    }
    // TODO: DownButton
}

根据需要进行调整,以赋予其他键不同的效果。

从NumericUpDown派生您自己的类,并覆盖UpButton和DownButton方法:

using System;
using System.Windows.Forms;

public class MyUpDown : NumericUpDown {
    public override void UpButton() {
        decimal inc = this.Increment;
        if ((Control.ModifierKeys & Keys.Control) == Keys.Control) this.Increment *= 10;
        base.UpButton();
        this.Increment = inc;
    }
    // TODO: DownButton
}

根据需要进行调整,以赋予其他键不同的效果。

这有点粗糙,但它比另一个答案稍微简单,但并不更好。对于问题的第二部分,您只需要使用基于当前值的计算替换100/10/1

在NumericUpDown nUpDown的keydown事件中,将默认增量设置为100或其他值


这有点粗糙,但它比另一个答案简单一点,但也不是更好。对于问题的第二部分,您只需要用基于当前值的计算替换100/10/1

在NumericUpDown nUpDown的keydown事件中,将默认增量设置为100或其他值


谢谢,_KeyDown比_keydup更可取吗?如果按住键,KeyDown会重复,而keydup只会在释放时触发Hanks,_KeyDown比_keydup更可取吗?如果按住键,KeyDown会重复,而keydup只会在释放时触发