Sae*_*ani 14 .net c# string numericupdown winforms
在WinForms中是否可以在NumericUpDown控件中显示文本?例如,我想显示我的numericupdown控件中的值是微安培,所以它应该像"1 uA".
谢谢.
Cod*_*ray 28
标准控件中没有内置的功能.但是,通过创建从NumericUpDown类继承的自定义控件并重写UpdateEditText方法来相应地格式化数字,可以相当容易地添加它.
例如,您可能具有以下类定义:
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";
}
}
Run Code Online (Sandbox Code Playgroud)
或者,要获得更完整的实现,请参阅此示例项目:带有单位度量的NumericUpDown