110,536
社区成员
发帖
与我相关
我的任务
分享
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (this.textBox1.Text.Trim().Length == 6)
{
e.Handled = true;
}
if (this.textBox1.Text.Trim().Length < 3)
{
if (((e.KeyChar < 97 || e.KeyChar > 122) && (e.KeyChar != 8) && (e.KeyChar != 46)) && ((e.KeyChar < 65 || e.KeyChar > 90) && (e.KeyChar != 8) && (e.KeyChar != 46)))
{
e.Handled = true;
}
}
else if (this.textBox1.Text.Trim().Length >=3)
{
if ((e.KeyChar < 48 || e.KeyChar > 57) && (e.KeyChar != 8) && (e.KeyChar != 46))
{
e.Handled = true;
}
}
}
MaskedTextBox1.Mask = "LLL000";
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (this.textBox1.Text.Trim().Length == 6)
{
e.Handled = true;
}
if (this.textBox1.Text.Trim().Length < 3)
{
if ((e.KeyChar < 97 || e.KeyChar > 122) && (e.KeyChar != 8) && (e.KeyChar != 46))
{
e.Handled = true;
}
}
else if (this.textBox1.Text.Trim().Length >=3)
{
if ((e.KeyChar < 48 || e.KeyChar > 57) && (e.KeyChar != 8) && (e.KeyChar != 46))
{
e.Handled = true;
}
}
}
private void Form1_Load(object sender, EventArgs e)
{
this.textBox1.MaxLength = 6;
}
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (this.textBox1.Text.Length <3)
{
if (char.IsLetter(e.KeyChar) == true || char.IsControl(e.KeyChar) == true)
{
e.Handled = false;
}
else
{
e.Handled = true;
}
}
if (this.textBox1.Text.Trim().Length >= 3)
{
if (char.IsDigit(e.KeyChar) == true || char.IsControl(e.KeyChar) == true)
{
e.Handled = false;
}
else
{
e.Handled = true;
}
}