winfrom 判断textbox 我想在textbox重判断只允许输入数字和冒号,且第一个不允许为冒号该怎么实现 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 private void textBox1_TextChanged(object sender, EventArgs e) { Regex r = new Regex(@ "^\d*$|\:"); if (!r.IsMatch(this.textBox1.Text)) { textBox1.Text=s;//恢复 textBox1.SelectionStart = s.Length; } else s=textBox1.Text; } Regex r = new Regex(@ "^\d*$|\:"); if (!r.IsMatch(this.textBox1.Text)) { textBox1.Text=s;//恢复 textBox1.SelectionStart = s.Length; } else s=textBox1.Text; private void textBox1_KeyPress(object sender, KeyPressEventArgs e) { if ((e.KeyChar >= '0' && e.KeyChar <= '9') || e.KeyChar == 8) { e.Handled = false; } else if (e.KeyChar == 58) { if (textBox1.Text.Length > 0) { e.Handled = false; } else { e.Handled = true; } } else { e.Handled = true; } } string s=string.Empty; if (textBox1.Text != ":") { Regex r = new Regex(@"^\d*$|\:"); if (!r.IsMatch(this.textBox1.Text)) { textBox1.Text = s;//恢复 textBox1.SelectionStart = s.Length; } else s = textBox1.Text; } else { textBox1.Text=s; } private void textBox4_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar==':') { e.Handled = true; } }数字字母同样实现的方式很多 哪不对了,写在KeyPress事件中 先事件,keypress事件,在里面用正则判断。。 WinForm界面上如何拖动控件? WF流程配置 贪吃蛇游戏教程 请教如何根据dtGridView的大小自适应调整Winform的大小 利用线程显示数据 为什么? 错误 CS0206: 属性或索引器不得作为 out 或 ref 参数传递 ASP.NET2.0 中TreeView控件:如何做到点击节点而不刷新页面? 急啊,100分求用c#开发网站在线支付的思路, 根据C /C++源码生成流程图算法 如何获得TOOLSTRIP 上按钮的位置 菜鸟问题又来了,VS2005(08)中如何使用向导对话框 求一正则 【非负整数和非负浮点数】
{
Regex r = new Regex(@ "^\d*$|\:");
if (!r.IsMatch(this.textBox1.Text))
{
textBox1.Text=s;//恢复
textBox1.SelectionStart = s.Length;
}
else
s=textBox1.Text;
}
if (!r.IsMatch(this.textBox1.Text))
{
textBox1.Text=s;//恢复
textBox1.SelectionStart = s.Length;
}
else
s=textBox1.Text;
{
if ((e.KeyChar >= '0' && e.KeyChar <= '9') || e.KeyChar == 8)
{ e.Handled = false;
}
else if (e.KeyChar == 58)
{
if (textBox1.Text.Length > 0)
{
e.Handled = false;
}
else
{
e.Handled = true;
}
}
else
{
e.Handled = true;
}
}
if (textBox1.Text != ":")
{
Regex r = new Regex(@"^\d*$|\:");
if (!r.IsMatch(this.textBox1.Text))
{
textBox1.Text = s;//恢复
textBox1.SelectionStart = s.Length;
}
else
s = textBox1.Text;
}
else
{
textBox1.Text=s;
}
private void textBox4_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar==':')
{
e.Handled = true;
}
}数字字母同样实现的方式很多
哪不对了,写在KeyPress事件中