高手来修改C#错误代码!

来源:百度知道 编辑:UC知道 时间:2024/09/20 03:03:59
private void TextBox_KeyUp(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
System.Diagnostics.Process.Start("iexplore", "http://xxxxxxx/?ID= " + TxtShow.Text);
}

附:TextBox里只能输0-9的数字..代码精短就加分..
在限制...限制为只能输..不过好像我已经找到答案了..
大家就改代码吧!

加一个KeyDown事件:
private void TextBox_KeyDown(object sender, KeyEventArgs e)
{
e.SuppressKeyPress = !(e.KeyCode == Keys.Enter || (e.KeyValue>=48 && e.KeyValue<=57) || e.KeyValue == 8);
}

这是判断是否是1—9数字的 剩下的由你来完成吧!!
if (char.IsDigit(Convert.ToChar(this.TxtShow.Text)))
{
if (e.KeyCode == Keys.Enter)
System.Diagnostics.Process.Start("iexplore", "http://xxxxxxx/?ID= " + TxtShow.Text);

}
else
{
return;
}

试试看,可惜我的卸掉了。。。破机器阿破机器

if(!(e.KeyChar >= (char)Keys.D0 && e.KeyChar <= (char)Keys.D9 || e.KeyChar == (char)Keys.Back || e.KeyChar == (char)Keys.Delete || e.KeyChar == (char)Keys.Enter ))
{
e.Handled = true;
}
在KeyPress事件里

if(Syst