I am creating a Visual c# version of minesweeper and have created an array which without identifying a left or right click both work. Obviously in minesweeper there needs to be a right click for flag and a left click to clear. I started by developing the clear with just the .Click and that works but when I call upon the mouseButton to click with a left or a right this does not work.
I tried moving around the order of the IF but this causes other errors within my code so I was hoping I could gain some advice on how to rewrite my code to make it work? Here's my entire section with the mouse information inside.
for (int a = 0; a < BoardSize; a++)
{
for (int d = 0; d < BoardSize; d++)
{
cov[a, d] = new PictureBox();
cov[a, d].Height = 30; //Same size as the Hid pictureboxes
cov[a, d].Width = 30;
cov[a, d].Left = (a * 40) + 25;
cov[a, d].Top = (d * 40) + 25;
cov[a, d].BackColor = Color.Plum; //Colour of the cover layer
cov[a, d].BringToFront();
cov[a, d].Name = a + d.ToString();
this.Controls.Add(cov[a, d]);
if (e is MouseEventArgs)
{
MouseButtons mouseButton = (e as MouseEventArgs).Button;
if (mouseButton == MouseButtons.Left)
{
cov[a, d].Click += leftClick;
}
else if (mouseButton == MouseButtons.Right)
{
MessageBox.Show("Right mouse button is clicked");
}
}
}
}