嗨,我在这里遇到问题。因此,您可以看到,每当单击 txtBtn0 和 txtBtn1 时,它都会增加自己的数组,然后将其用于 squareChecked 字符串。但是我首先要做的是,如果 txtBtn0 和 txtBtn1 没有被点击,就会给出一个错误信息。但它不会弹出任何东西。
public partial class MainForm : Form
{
public int[] clickNumBoxArray = Enumerable.Repeat(1, 81).ToArray();
public MainForm()
{
InitializeComponent();
} ... ... ...
private void btn1_Click(object sender, EventArgs e) {
UserSquare checkClickedBox = new UserSquare();
string checkClickBox = checkClickedBox.squareChecked();
if (checkClickedBox == null) {
MessageBox.Show("You did not enter any text on the form");
}
}
private void txtBtn1_Click(object sender, EventArgs e) {
clickNumBoxArray[1]++;
if (clickNumBoxArray[1] % 2 == 0) {
txtBtn1.BackColor = System.Drawing.Color.DarkOrange;
} else {
txtBtn1.BackColor = System.Drawing.Color.WhiteSmoke;
}
}
private void txtBtn0_Click(object sender, EventArgs e) {
clickNumBoxArray[0]++;
if (clickNumBoxArray[0] % 2 == 0) {
txtBtn0.BackColor = System.Drawing.Color.DarkOrange;
} else {
txtBtn0.BackColor = System.Drawing.Color.WhiteSmoke;
}
}
这是另一个类
class UserSquare { public string squareChecked() { string clickedBoxes = null; MainForm numBoxArray = new MainForm(); int[] clickNumBoxArray = numBoxArray.clickNumBoxArray; for (int i = 0; i < 81; i++) { if (clickNumBoxArray[i] % 2 == 0) { clickedBoxes += "txtBtn" + i + ", "; } } return clickedBoxes; }