Hi i am having a problem here. So you can see whenever the txtBtn0 and txtBtn1 is clicked it increments its own array which is then used for squareChecked string. But what I want to do first is to give out an error message if txtBtn0 nor txtBtn1 is not clicked. But it does not pop up anything.
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;
}
}
This is the other class
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; }
About
IndexOutOfRange ExceptionYour problem is that you implement your list hereas starts from 1 and finished 80 = 80 elements
but in method your
for loopstarts from 0 and finished 81 = 81 elementsand about controlling by error.. simply and tricky.. you can implement an
internal/public booleanas defaultfalseand set totruein a mouse event as you need (i.e.mouseclick event)..end of your error method or where you need else, set to back false to be ready for another click-event controllingAbout ButtonClick not fire its event (if im not misunderstood) : Did you deleted your some methods of buttons ? could you been forgot to implement it back ?
open your design mode click once onto your controls which you want to check, and then open properties => events.. if your events implemented then it should be as so : (i.e.)
(property) MouseClick (value) Button1_MouseClick