我让用户使用两个NumericUpDown
控件为计划任务运行选择日期/时间。在NumericUpDown控件中显示“00”而不是“0”
我想要用一个前导0填充一位数值,以便显示09:00
而不是9:0
。
我让用户使用两个NumericUpDown
控件为计划任务运行选择日期/时间。在NumericUpDown控件中显示“00”而不是“0”
我想要用一个前导0填充一位数值,以便显示09:00
而不是9:0
。
的决定性解决方案是使用一个与DateTimePicker
组ShowUpDown
到True
并Format
集到Time
或Custom
。在后一种情况下,您可以使用hh:mm
或HH:mm
作为自定义格式。
这不适用于NumericUpDown控件。
我有一个聪明的想法〜 为什么不把一个覆盖numericupdown控件的文本框部分的文本框(只显示numericupdown的滚动条)?
设置您的文本框为“00”作为初始值,然后禁用它,以便用户无法控制您的文本框。
然后输入这些代码:
Private Sub numericupdown1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ndFrom.ValueChanged
If numericupdown1.Value < 10 Then
textbox1.Text = "0" & numericupdown1.Value
Else
textbox1.Text = numericupdown1.Value
End If
End Sub
是的,但这有点ha,,不太干净。我想你很可能会使用标签,但不是文本框。 – 2011-02-17 10:44:03
class CustomNumericUpDown:System.Windows.Forms.NumericUpDown
{
protected override void OnTextBoxTextChanged(object source, EventArgs e)
{
TextBox tb = source as TextBox;
int val = 0;
if (int.TryParse(tb.Text,out val))
{
if (val < 10)
{
tb.Text = "0" + val.ToString();
}
}
else
{
base.OnTextBoxTextChanged(source, e);
}
}
}
今天早上我不得不这样做,并为我的Windows窗体应用程序提出了一个自定义数字Up Down。你应该能够很容易地改变这个VB.NET。
class MyNumericUpDown : System.Windows.Forms.NumericUpDown
{
public override string Text
{
get
{
return base.Text;
}
set
{
if (value.Length < 2)
value = "0" + value;
base.Text = value;
}
}
}
谢谢!那么我必须使用'DomainUpDown'。 – 2010-08-17 12:15:41