Hi,

Following is the issue im having....

Im working on a checkers game using c#. ive decided to set each checker within a picturebox that will be displayed inside a panel (gameboard) however the problem comes when I have to move the checkers. I could write code to move the checkers using mouse up, down and move, but problem is to do so I have to drag and drop 24+ picture boxes into the panel to do so. I was thinking of comming up with a way of going PictureBox pb = new PictureBox() each time i needed a checker and then writing an event listener to it dynamically, but so far it doesnt seem to be working....

I really hate to have to drag drop 24 checkers and write mouse move code for each :(

does anyone know if such a thing is possible? what would be the best approach to create the checkers ?

You don't have to write mouse move code for each. You just have to write it once.

Try something like this:

private void Form1_Load(object sender, EventArgs e)
        {
            PictureBox pb = new PictureBox();
            pb.Click += new EventHandler(ClickEvent);
            pb.BorderStyle = BorderStyle.Fixed3D;
            panel1.Controls.Add(pb);
        }

        private void ClickEvent(object sender, EventArgs e)
        {
            MessageBox.Show("Clicked");
        }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.