在winform的NumericUpDown控制可变增量步取决于是否移位/ Ctrl键/等。是pressed [英] Variable increment step in WinForm NumericUpDown control depending on whether Shift/Ctrl/etc. are pressed

查看:1081
本文介绍了在winform的NumericUpDown控制可变增量步取决于是否移位/ Ctrl键/等。是pressed的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想是有点类似于在WinForm设计在Visual Studio中发生了什么,说VS2010。如果我把一个按钮,然后选择它,并使用箭头键,将5个像素在任何方向上,我选择用pressing右键左右移动。现在,如果我认为无论是Shift或Ctrl键一个作为修饰我做的(忘了是哪一个,不好意思),则该按钮将仅由1像素的一次移动。

What I want is somewhat similar to what happens in a WinForm designer in Visual Studio, say VS2010. If I place a button and select it and use arrow keys, it will move around by 5 pixels in whatever direction I chose by pressing the right key. Now, if I hold either a Shift or a Ctrl modifier as I do that (forgot which one, sorry), then the button will move only by 1 pixel at a time.

我希望这发生在我在C#的WinForm程序NumericUpDown控件。比方说,一个默认增量是100.0,和一个较小的增量是10.0。甚至更小的增量(如果可能的话)可以是1.0。我如何能做到这一点的任何提示?

I want this to happen with my NumericUpDown control in a C# WinForm app. Let's say a default increment is 100.0, and a smaller increment is 10.0. An even smaller increment (if possible) can be 1.0. Any hints on how can I do that?

我希望我不需要问这是一个单独的问题:我也具有增量依赖于输入的电流值的想法玩弄。再说了,我可以输入一个金额范围是1〜100十亿。那么我想默认的,小的,小的增量值依赖于输入的值。我可以找出确切的公式我自己。

Hopefully I do not need to ask this as a separate question: I am also toying with the idea of having the increment be dependent on the current value entered. Say, I can enter a dollar amount anywhere between 1 and 100 billion. I then want the default, small, and smaller increment values be dependent on the value entered. I can figure out the exact formula myself.

推荐答案

这的NumericUpDown派生自己的类和重写UpButton()和DownButton()方法:

Derive your own class from NumericUpDown and override the UpButton() and DownButton() methods:

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
}

扭捏必要给其他按键不同的效果。

Tweak as necessary to give other keys different effects.

这篇关于在winform的NumericUpDown控制可变增量步取决于是否移位/ Ctrl键/等。是pressed的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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