private void initializeBoard() { bool cutoff; for (int i = 0; i <= 7; i++) { for (int j = 0; j <= 5; j++) { cutoff = true; if (i == 2 || i == 3 || i == 4 || i == 5) { if (j == 4 || j == 5) { cutoff = false; } } if (cutoff == true) { btnSeat[i, j] = new Button(); btnSeat[i, j].Width = 80; btnSeat[i, j].Height = 80; btnSeat[i, j].Left = (90 * i); if (i == 2) btnSeat[i, j].Left = (120 * i); if (i == 3) btnSeat[i, j].Left = (110 * i); if (i == 4) btnSeat[i, j].Left = (130 * i); if (i == 5) btnSeat[i, j].Left = (122 * i); if (i == 6) btnSeat[i, j].Left = (125 * i); if (i == 7) btnSeat[i, j].Left = (120 * i); btnSeat[i, j].Top = (90 * j); btnSeat[i, j].Image = Image.FromFile("../../monitor.png"); pnlSeat.Controls.Add(btnSeat[i, j]); String buttonName = "btn" + i + j; btnSeat[i, j].Name = buttonName; btnSeat[i, j].Text = buttonName; btnSeat[i, j].Click += new EventHandler(seat_Click); if (btnSeat[i, j].Text == clientIP) { btnSeat[i, j].Image = Image.FromFile("../../ol.png"); btnSeat[i, j].BeginInvoke(new MethodInvoker(() => btnSeat[i, j].Text = sClientHost)); } } } } btnSeat[0, 0].Text = "192.168.1.2"; btnSeat[0, 1].Text = "192.168.1.5"; btnSeat[0, 2].Text = "192.168.1.8"; } I am new to c#. Any help would be much appreciated.
bool cutoff; for (int i = 0; i <= 7; i++) { for (int j = 0; j <= 5; j++) { cutoff = true; if (i == 2 || i == 3 || i == 4 || i == 5) { if (j == 4 || j == 5) { cutoff = false; } } if (cutoff == true) { btnSeat[i, j] = new Button(); btnSeat[i, j].Width = 80; btnSeat[i, j].Height = 80; btnSeat[i, j].Left = (90 * i); if (i == 2) btnSeat[i, j].Left = (120 * i); if (i == 3) btnSeat[i, j].Left = (110 * i); if (i == 4) btnSeat[i, j].Left = (130 * i); if (i == 5) btnSeat[i, j].Left = (122 * i); if (i == 6) btnSeat[i, j].Left = (125 * i); if (i == 7) btnSeat[i, j].Left = (120 * i); btnSeat[i, j].Top = (90 * j); btnSeat[i, j].Image = Image.FromFile("../../monitor.png"); pnlSeat.Controls.Add(btnSeat[i, j]); String buttonName = "btn" + i + j; btnSeat[i, j].Name = buttonName; btnSeat[i, j].Text = buttonName; btnSeat[i, j].Click += new EventHandler(seat_Click); if (btnSeat[i, j].Text == clientIP) { btnSeat[i, j].Image = Image.FromFile("../../ol.png"); btnSeat[i, j].BeginInvoke(new MethodInvoker(() => btnSeat[i, j].Text = sClientHost)); } } } } btnSeat[0, 0].Text = "192.168.1.2"; btnSeat[0, 1].Text = "192.168.1.5"; btnSeat[0, 2].Text = "192.168.1.8";
for (int j = 0; j <= 5; j++) { cutoff = true; if (i == 2 || i == 3 || i == 4 || i == 5) { if (j == 4 || j == 5) { cutoff = false; } } if (cutoff == true) { btnSeat[i, j] = new Button(); btnSeat[i, j].Width = 80; btnSeat[i, j].Height = 80; btnSeat[i, j].Left = (90 * i); if (i == 2) btnSeat[i, j].Left = (120 * i); if (i == 3) btnSeat[i, j].Left = (110 * i); if (i == 4) btnSeat[i, j].Left = (130 * i); if (i == 5) btnSeat[i, j].Left = (122 * i); if (i == 6) btnSeat[i, j].Left = (125 * i); if (i == 7) btnSeat[i, j].Left = (120 * i); btnSeat[i, j].Top = (90 * j); btnSeat[i, j].Image = Image.FromFile("../../monitor.png"); pnlSeat.Controls.Add(btnSeat[i, j]); String buttonName = "btn" + i + j; btnSeat[i, j].Name = buttonName; btnSeat[i, j].Text = buttonName; btnSeat[i, j].Click += new EventHandler(seat_Click); if (btnSeat[i, j].Text == clientIP) { btnSeat[i, j].Image = Image.FromFile("../../ol.png"); btnSeat[i, j].BeginInvoke(new MethodInvoker(() => btnSeat[i, j].Text = sClientHost)); } } }