Battleship game

gflint

New member
Joined
Nov 20, 2009
Messages
3
Location
Montana
Programming Experience
5-10
I am trying to build a battleship game. The project is giving me one minor difficulty (so far). I do not know how to create the game board made up of 100 buttons. I can obviously drag and drop 100 buttons onto the form but this lacks a certain style, it would also be a pain. How do I create a form covered with required array of buttons automatically? VB6 had a control array method that would do this task fairly simple.
 
I would suggest adding a TableLayoutPanel to the form and configure it as desired. You can then add the Buttons in code using a loop. You just call Controls.Add on the TableLayoutPanel and the Buttons will all be added in a grid.
 
If you do want to add them in the designer then I'd still recommend the TLP, which will make is much easier to maintain a grid, especially if the form can resize. You can add and configure the TLP, select it and then just double-click the Button in the Toolbox 100 times. Alternatively, you can copy and paste multiple controls in the designer simultaneously.
 
Now I just have the little detail of figuring out what a TableLayoutPanel is. I will figure it out, that is what makes this whole programming thing fun.
 
Back
Top