有NumericUpDown控件中的文本,该号码后 [英] Having text inside NumericUpDown control, after the number

查看:331
本文介绍了有NumericUpDown控件中的文本,该号码后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能在的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 类,并覆盖了<一加href="http://msdn.microsoft.com/en-us/library/system.windows.forms.numericupdown.updateedittext.aspx"><$c$c>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与计量单位

这篇关于有NumericUpDown控件中的文本,该号码后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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