2011-05-13 287 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

相關問題