Textbox限制輸入數字

因為常常用到,但又總是記不得,所以,先在這裡做記錄一下。
private void tbHeight_KeyPress(object sender, KeyPressEventArgs e)
{
if (char.IsDigit(e.KeyChar) == false && char.IsControl(e.KeyChar) == false && e.KeyChar != '.')
{
e.Handled = true;
}
}

PS.「e.KeyChar != '.'」這是用於有小數點的時候


2016-11-14 21:17:51

I said something before.....
Label 在 PictureBox 上背景不能透明 2021-05-24 06:32
C# 字串分割 2016-07-28 20:25
LINQ筆記 2016-07-27 03:33
SQL Server的記錄檔無限成長 2015-11-02 05:47
安裝MySQL ODBC 5.2錯誤 – Error 1918 2014-02-03 19:27
在Reporting Service報表上顯示QRCode 2013-04-01 02:59
SQL Server DB管理筆記 2012-07-05 20:21
還原MSSQL遇到「備份組包含現有的XXX資料庫以外的資料庫備份」的錯誤 2012-05-15 12:35
Informix計算兩時間的差距 2010-08-12 06:01
ReportViewer顯示LocalReport及ServerReport 2010-05-24 04:13
SQL Server取得當月第一天及最後一天 2010-01-19 00:00
簡單的對DataTable做Distinct 2009-09-20 22:18
使用 svcutil 編譯 WCF 錯誤解法 2009-07-09 07:59
PHP加載MSSQL函式庫 2008-10-20 08:54
資料庫抓取固定筆數資料 2008-09-18 22:27