2011-05-13 284 views

回答

5

我做了一个小实验,发现这种解决方法:

private void numericUpDown1_KeyPress(object sender, KeyPressEventArgs e) 
    { 
     if (e.KeyChar < 48 || e.KeyChar > 57) 
     { 
      e.Handled = true; 
     } 
    } 

这样你将不能够输入千位分隔符要么,但你可以添加,通过首次发现拿出千位分隔符是什么,并允许。

+0

谢谢。它应该工作 – umbersar 2011-05-15 04:04:17

+3

你可能想要退格 - 检查上面的(e.KeyChar!= 8)。 – amolbk 2013-03-01 10:24:09

+0

@amolbk - 是和其他键(箭头,首页,结束,Ctrl-C,V和X)也可能是有用的。 – 2013-03-01 11:28:35

0

如果您使用的是AjaxControlToolkit,你可以只用NumericUpDownExtender结合FilteredTextBoxExtender:

<asp:FilteredTextBoxExtender ID="FilteredTextBoxExtender" runat="server" TargetControlID="TextBoxNums" FilterType="Numbers"> 
</asp:FilteredTextBoxExtender> 
<asp:NumericUpDownExtender ID="NumericUpDownExtender" runat="server" TargetControlID="TextBoxNums" Width="10"> 
</asp:NumericUpDownExtender> 
<asp:TextBox ID="TextBoxNums" runat="server"></asp:TextBox> 
+0

糟糕我只注意到您使用的是Windows窗体而不是Web窗体 – msnorth 2013-05-24 16:41:44

0

如果你有机会获得的DevExpress控制,你应该使用SpinEdit控制,并设置其Properties.IsFloatValue

相关问题