C# TextBox只能夠輸入數字及小數點 this.TextBox1.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.TextBoxF_32B_2_KeyPress); private void TextBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
private void InitializeComponent()
{
if (e.KeyChar.CompareTo('\b') == 0)
e.Handled = false;
else if ((e.KeyChar.CompareTo('0') < 0 || e.KeyChar.CompareTo('9') > 0) && !(e.KeyChar.CompareTo('.') == 0)) //比較輸入值的範圍是否超出數字
e.Handled = true;// Handled 為是否鎖住輸入
}
全站熱搜
留言列表