hi guys i kinda need help with my project, i never dealt with GUI and i am stuck on this project. if anyone can help plz.
the project is a MAZE but to start i wanna know how to to start the First event handler:

public partial class MazeBoard : Form
{
public const int HorizontalIncrement = 49;
public const int VerticalIncrement = 47;
public const int VerticalWallStartX = 10;
public const int VerticalWallStartY = 23;
public const int HorizontalWallStartX = 24;
public const int HorizontalWallStartY = 9;
public const int CellGridStartX = 24;
public const int CellGridStartY = 23;
public const int Row = 10;
public const int Column = 10;
public const int WallRows = 11;
public const int WallColumns = 11;
public const int VerticalWallTextBoxWidth = 8;
public const int VerticalWallTextBoxHeight = 25;
public const int HorizontalWallTextBoxWidth = 29;
public const int HorizontalWallTextBoxHeight = 8;
public const int CellTextBoxWidth = 29;
public const int CellTextBoxHeight = 25;
public const int StartTabIndex = 0;
private Button[,] uxCell = new Button[Row, Column];
private Button[,] uxVerticalWall = new Button[WallRows, WallColumns];
private Button[,] uxHorizontalWall = new Button[WallRows, WallColumns];
public MazeBoard()
{
InitializeComponent();
AddGrid();
}
private void AddGrid()
{
for (int i = 0; i < Row; i++)
{
for (int j = 0; j < Column; j++)
{
int tabIndex = StartTabIndex;
Button box = new Button();



box.Location = new Point(CellGridStartX + j * HorizontalIncrement, CellGridStartY + i * VerticalIncrement);
box.Name = "uxGridValue[" + i + "," + j + "]";
box.FlatStyle = FlatStyle.Popup;
box.BackColor = Color.Silver;
box.Size = new Size(CellTextBoxWidth, CellTextBoxHeight);
box.TabIndex = tabIndex++;
Controls.Add(box);
uxCell[i, j] = box;
}

}
for (int i = 0; i < WallRows; i++)
{
for (int j = 0; j < Column; j++)
{
int tabIndex = StartTabIndex;
Button box1 = new Button();
box1.FlatStyle = FlatStyle.Flat;
box1.Location = new Point(HorizontalWallStartX + j * HorizontalIncrement, HorizontalWallStartY + i * VerticalIncrement);
box1.Name = "uxGridValue[" + i + "," + j + "]";
box1.BackColor = Color.Silver;
box1.Size = new Size(HorizontalWallTextBoxWidth, HorizontalWallTextBoxHeight);
box1.TabIndex = tabIndex++;
Controls.Add(box1);
uxHorizontalWall[i, j] = box1;



}
}
for (int i = 0; i < Row; i++)
{
for (int j = 0; j < WallColumns; j++)
{
int tabIndex = StartTabIndex;

Button box2 = new Button();
box2.FlatStyle = FlatStyle.Flat;
box2.Location = new Point(VerticalWallStartX + j * HorizontalIncrement, VerticalWallStartY + i * VerticalIncrement);
box2.Name = "uxGridValue[" + i + "," + j + "]";
box2.BackColor = Color.Silver;
box2.Size = new Size(VerticalWallTextBoxWidth, VerticalWallTextBoxHeight);
box2.TabIndex = tabIndex++;
Controls.Add(box2);
uxVerticalWall[i, j] = box2;
}
}
}

I wanna creat an event handler that change the Button Color to Black for the Vertical and Horizontal Walls when Pressed

I tried :

private void uxCell_Click(object sender, EventArgs e)
{
for(int i=0; i< row; i++){
for(int j=0; j<Column; j++){
if( uxVerticalWall[ i , j ] == (Button)sender){
uxVerticalWall[ i , j ].BackColor= Color.Black
}
}
}
}

But this event handler doesnt work at all ><?
help plz

for each button you have you need to assign the click event to a procedure that toggles the color, you dont need to do a loop throuhg your rows and columns necessarily, as the sender object will be your button you clicked, so, you culd just do

if ((Button)Sender.Backcolor!=Color.Black)
{
(Button)Sender.Backcolor=Color.Black;
}
else
{
(Button)Sender.Backcolor=Color.White;
}
This article has been dead for over six months. Start a new discussion instead.