日期:2014-05-17 浏览次数:20781 次
protected void TextBox1_TextChanged(object sender, EventArgs e)
{
string str = textBox1.Text + textBox2.Text + textBox3.Text;
int keycharvalue = Encoding.ASCII.GetBytes(TextBox1.Text.Substring(TextBox1.Text.Length - 1,1))[0];
if (EnterJudgmentMethod(keycharvalue, str))
TextBox1.Text = TextBox1.Text.Substring(0, TextBox1.Text.Length - 1);
}
/// <summary>
/// 控制键盘输入方法
/// </summary>
/// <param name="KeyCharValue">键盘输入的ASCII值——e.KeyChar值</param>
/// <param name="str">输入的字符集合</param>
/// <returns></returns>
public static bool EnterJudgmentMethod(int KeyCharValue, string str)
{
bool result = true;
byte[] t = Encoding.ASCII.GetBytes(str);
foreach (byte b in t)
{
if (KeyCharValue == b)
result = false;
}
return result;
}