C# 有6个Textbox如何输入不同数字

发布网友 发布时间:2024-10-24 02:13

我来回答

4个回答

热心网友 时间:6分钟前

晕!!自己不让回答自己的阿!
我刚才自己写的,感觉麻烦,不过解决了
private void textBox1_TextChanged(object sender, EventArgs e)
{
if (textBox1.Text == textBox2.Text || textBox1.Text == textBox3.Text || textBox1.Text == textBox4.Text || textBox1.Text == textBox5.Text || textBox1.Text == textBox6.Text)
{
textBox1.Text = string.Empty;
}
}

private void textBox2_TextChanged(object sender, EventArgs e)
{
if (textBox2.Text == textBox1.Text || textBox2.Text == textBox3.Text || textBox2.Text == textBox4.Text || textBox2.Text == textBox5.Text || textBox2.Text == textBox6.Text)
{
textBox2.Text = string.Empty;
}
}

private void textBox3_TextChanged(object sender, EventArgs e)
{
if (textBox3.Text == textBox1.Text || textBox3.Text == textBox2.Text || textBox3.Text == textBox4.Text || textBox3.Text == textBox5.Text || textBox3.Text == textBox6.Text)
{
textBox3.Text = string.Empty;
}
}

private void textBox4_TextChanged(object sender, EventArgs e)
{
if (textBox4.Text == textBox1.Text || textBox4.Text == textBox2.Text || textBox4.Text == textBox3.Text || textBox4.Text == textBox5.Text || textBox4.Text == textBox6.Text)
{
textBox4.Text = string.Empty;
}
}

private void textBox5_TextChanged(object sender, EventArgs e)
{
if (textBox5.Text == textBox1.Text || textBox5.Text == textBox2.Text || textBox5.Text == textBox3.Text || textBox5.Text == textBox4.Text || textBox5.Text == textBox6.Text)
{
textBox5.Text = string.Empty;
}
}

private void textBox6_TextChanged(object sender, EventArgs e)
{
if (textBox6.Text == textBox1.Text || textBox6.Text == textBox2.Text || textBox6.Text == textBox3.Text || textBox6.Text == textBox4.Text || textBox6.Text == textBox5.Text)
{
textBox6.Text = string.Empty;
}
}

热心网友 时间:4分钟前

应该写一个函数拿到数组里面去比对

热心网友 时间:1分钟前

花朵说的不错

热心网友 时间:8分钟前

private void textBox_Control_KeyDown(object sender, KeyEventArgs e)
{
//排除不适合的控制键
if((e.KeyValue >=33 && e.KeyValue <= 36)
|| (e.KeyValue >=45 && e.KeyValue <= 46)
|| (e.KeyValue >=48 && e.KeyValue <= 57)
|| (e.KeyValue >=65 && e.KeyValue <=90)
|| (e.KeyValue >=96 && e.KeyValue <=107)
|| (e.KeyValue >=109 && e.KeyValue <=111)
|| (e.KeyValue >=219 && e.KeyValue <=222))
{
//检查冲突
foreach(Control c in groupBox_KeySet.Controls)
{
Control tempC = c as TextBox;
if(tempC != null && ((TextBox)tempC).Text != "")
{
if(((int)((TextBox)tempC).Tag) == e.KeyValue)
{
((TextBox)tempC).Text = "";
((TextBox)tempC).Tag = Keys.None;
}
}
}
((TextBox)sender).Text = e.KeyCode.ToString();
((TextBox)sender).Tag = (Keys)e.KeyValue;
}
}

上面的代码是以前我做的小游戏设置控制键的代码
如果有重复则自动替换,比如“上”本来是“w”
如果你设置“下”为“w”的话,则“上”的“w”自动清空

具体细节可以问我

//既然你能看懂,那你就把代码稍微改动一下就行了呗,

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com