//只允许输入1-31之间的数字
int i_HID = 0;
if (!int.TryParse(txtGroupHID.Text, out i_HID) || i_HID > 31 || i_HID<=0)
{
Bestway.Windows.Controls.MessageBoxEx.Show("输入值错误,请重新输入1-31之间的有效数字!","错误",MessageBoxButtons.OK,MessageBoxIcon.Error );
return;
}
//只允许输入数字
private void txtSum_KeyPress(object sender, KeyPressEventArgs e)
{
if ((e.KeyChar != 8 && !char.IsDigit(e.KeyChar))&&e.KeyChar!=13)
{
MessageBox.Show("商品数量只能输入数字","操作提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
e.Handled = true;
}
}
.
//e.KeyChar 8为back,32为空格,13回车键
//只允许输入数字和字母
private void txtGUID_Leave(object sender, EventArgs e)
{
if(checkIsLetterOrDigit(txtGUID.Text))
{
CommControls.MessageBoxEx.MessageBoxEx.Show("摄像头GUID只能输入数字和字母", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
txtGUID.Text = "";
txtGUID.Focus();
}
}
private bool checkIsLetterOrDigit(string str)
{
bool isError=false;
foreach (char c in str)
{
if (!char.IsLetterOrDigit(c) || ((int)c > 0x4E00 && (int)c < 0x9FA5))
{
isError = true;
break;
}
}
return isError;
}
public bool IsChinese(char c)
{
return (int)c > 0x4E00 && (int)c < 0x9FA5;
}
.