有NumericUpDown控件中的文本,该号码后控件、文本、号码、NumericUpDown

2023-09-04 00:05:52 作者:爱情眠于流年

是否有可能在的WinForms显示NumericUpDown控件内的文本?例如,我想告诉我的NumericUpDown控件中的值是微ampers所以应该是像1微安。

Is it possible in WinForms to show a text inside a NumericUpDown control? For example I want to show the value in my numericupdown control is micro ampers so it should be like "1 uA".

感谢。

推荐答案

有内置的标准控件中没有这样的功能。然而,这也很容易通过创建一个自定义的控件,继承自的NumericUpDown 类,并覆盖了UpdateEditText方法相应格式化数字。

There's no such functionality built into the standard control. However, it's fairly easy added by creating a custom control that inherits from the NumericUpDown class and overrides the UpdateEditText method to format the number accordingly.

例如,你可能有下面的类定义:

For example, you might have the following class definition:

public class NumericUpDownEx : NumericUpDown
{
    public NumericUpDownEx()
    {
    }

    protected override void UpdateEditText()
    {
        // Append the units to the end of the numeric value
        this.Text = this.Value + " uA";
    }
}

或者,一个更完整的实现,看到这个示例项目:的NumericUpDown与计量单位