C# TextBox十六(16)進位資料輸入限制函數
C# TextBox十六(16)進位資料輸入限制函數
private void TextBoxDataCheck(TextBox txt, KeyPressEventArgs e,int intLen)//16進位資料輸入限制函數 { if (e.KeyChar == 8)//刪除鍵要直接允許 { e.Handled = false; } else { if (txt.Text.Length < intLen)//長度限制在8 { if ((e.KeyChar >= 'a' && e.KeyChar <= 'f') || (e.KeyChar >= 'A' && e.KeyChar <= 'F') || (e.KeyChar >= '0' && e.KeyChar <= '9'))//限制0~9和A~F { e.Handled = false; } else { e.Handled = true; } } else { e.Handled = true; } } } private void txtcpu001_KeyPress(object sender, KeyPressEventArgs e) { TextBoxDataCheck(txtcpu001, e, 32); }