Well, as far as the 81 button go, no, putting them on the form in the designer is not the best approach. The biggest problem is that it isn't even slightly dynamic. At the very least, you need to be able to refer to the buttons by their coordinate. Ideally, you want to be able to create as many as you need to let the user select different field sizes, but that's up to you. One other thing I think I should point out is that while you
can use buttons, a more typical approach would be to draw the minefield yourself using a set of images that represents each possible state for a single grid square (flagged, empty, with a digit from 1 to 8, ect.). Again, up to you.
This isn't really an answer to you question, but a good place to start is with a specification. By writing out a detailed description of how your program is going to work, you make the actual process of coding much, much easier. I don't mean you necessarily have to detail how the program is implemented, but rather how it works from the user's point of view. But you need to be very specific. When you start banging code out (or throwing buttons on a form) before you know
exactly what the code is supposed to do, you are bound to run into more problems.
A specification would describe what the layout of the application is, exactly what happens when each button is clicked (for every state the button might be in), so on. Every little thing the user might do would be accounted for, and the result must be very well defined.
Back to your question, you probably don't want to put any minefield buttons on the form in the designer. Instead, you can create them in code and store them in an array. That way you refer to each button by it's location rather than a name.
First you need an array to hold the buttons. I recommend a 2-D array here.
Code:
[COLOR="Green"]' The comma indicates 2 dimensions, as in x[COLOR="Red"],[/COLOR] y[/COLOR]
Dim mineFieldButtons As Button(,)
That declares a variable to hold the array, but doesn't create the array. You will need to wait until the user specifies a size if you want to give him that option, but at some point you'll create the array.
Code:
[COLOR="Green"]' Create our array[/COLOR]
mineFieldButtons = [COLOR="Blue"]New Button(width, height) {}[/COLOR]
That doesn't give us any buttons, though, just an empty array. So now the important part: use a pair of nested for loops to create the actual buttons.
Code:
For X As Integer = 0 To Width - 1
For Y As Integer = 0 To Height - 1
[COLOR="Green"]' Create the button[/COLOR]
mineFieldButtons(X, Y) = [COLOR="Blue"]CreateButton(X, Y)[/COLOR]
[COLOR="Green"]' Add it to the form[/COLOR]
Controls.Add(mineFieldButtons(X,Y))
Next
Next
CreateButton is a function we have yet to define. It will not only create a button, but set its location and size.
Code:
Function CreateButton(X As Integer, Y As Integer) As Button
Dim result As New Button
[COLOR="Green"] // Set size
// Set location based on X and Y[/COLOR]
Return result
End Fuction
That will get you a grid of buttons, which you can access by coordinate, i.e.
mineFieldButtons(gridX, gridY).Text = "BOOM". The problem is you also need to (A) handle the click event for each of them and, (B) in the event handler, figure out which button was clicked. For (A) I recommend you research the AddHandler keyword.
For (B), a good approach would be to create a Point object that contains the buttons X and Y, and assign that Point to the button's .Tag property. This would be done in the CreateButton function. Then, in the event handler, you can cast the sender parameter to a button (using CType), get it's .Tag property, cast that to a Point, and then get the X and Y.
FYI, I've created a minesweeper clone before and the hardest part wasn't creating the minefield. Figuring out the "flood-fill"-style clearing of mineless spots when the user clicks on a button is much trickier. This is why I recommend the specification. As you write down
exactly what happens when the user clicks on a button, you realize that it's a little more complicated than it seems. Then you know what you're in for before you start writing the program.