Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am using the PictureBox class to create a checkerboard, and it not really working all that well. I've created the loop:

PictureBox[,] squares = new PictureBox[10,10];
        for (int i = 0; i < 10; i++)
            for (int j = 0; j < 10; j++)
                squares[i, j] = new PictureBox();
                squares[i,j].Image = Chess.Properties.Resources.square;
                squares[i, j].BackColor = Color.Transparent;

        for (int i = 0; i < 10; i++)
            for(int j = 0; j < 10; j++)
                squares[i, j].Location = new Point(i * 30, j * 30);
                this.Controls.Add(squares[i, j]);

It's supposed to create a 10x10 grid, and I added the image into the application resources. Each square is 20x20 pixels, and I loop by column. I thought it would work, but all I get is 6 images and the size just gets smaller.

Am I missing something? Or any good alternatives in creating a checkerboard without using PictureBox? Any thing with a MouseLeave, MouseHover, MouseClick, events I can use.

share|improve this question
The size per square is 20x20, but you position each one 30x30. I guess it should either be i*20, j*20 or i*40, j*40. – pimvdb Mar 27 '11 at 11:50
up vote 1 down vote accepted

If you're just doing basic drawing, you can create a single control (perhaps a UserControl subclass) and override the OnPaint() method. See for a sample tutorial. You'll also be able to override the various methods pertinent for mouse-handling.

share|improve this answer
I plan to update the image with the hover image and visited image for square that your hover on and already visited. Would would still advice the single control? – Bombcode Mar 27 '11 at 4:24
Yes; in fact, the fewer controls (child windows) you have, the better your drawing performance generally will be. You can capture the mouse motion events for the main control and use them to compute the hovered cell, store that information, and access it while drawing. – Josh Petrie Mar 27 '11 at 4:33

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.