C Sharp-如何在运行时使用numericUpDown控件为文本框值添加精度 [英] C sharp - How to add precision to textboxes values at runtime with numericUpDown control
问题描述
我在表单上有5-10个文本框,其中包含一些值..
和numericUpDown控件.
我必须根据numericupdown控件为文本框值添加精度..
例如
如果numericupdown控制值为1,则文本框值应类似于105.0
或者,如果numericupdown控制值为2,则文本框值应类似于105.00
这会在运行时发生,当我更改textbox的numericUpDown控件的值时,其精度也会发生变化...
thnxxxx
I have 5- 10 nos of textboxes on the form with some values..
and a numericUpDown control..
i have to add precision to textbox values according to numericupdown control..
for eg.
if numericupdown control value is 1 then textbox value should be like 105.0
or if numericupdown control value is 2 then textbox value should be like 105.00
this would happen at runtime, when i change the value of numericUpDown control value of textbox also change with precision...
thnxxxx
推荐答案
使用 String :: Format () [^ ]具有适当的精度设置的方法.
Use the String::Format()[^] method with the appropriate precision settings.
private void NumericUpDown1_ValueChanged(Object sender, EventArgs e)
{
int numberOfDecimals = (int)yourNumericUpDown.Value;
yourTextBox.Text = yourValue.ToSring("F" + numberOfDecimals.ToString());
}
private void NumericUpDown1_ValueChanged(Object sender, EventArgs e)
{
int numberOfDecimals = (int)yourNumericUpDown.Value;
yourTextBox.Text = yourValue.ToSring("F" + numberOfDecimals.ToString());
}
thnx用于您的解决方案
但是我必须同时为所有文本框添加精度....
thnx for ur solution
But I have to add precision to all textboxes at the same time....
这篇关于C Sharp-如何在运行时使用numericUpDown控件为文本框值添加精度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!