I am a novice in Visual Basic (I have been studying it at school for 2 months) and I have a problem with my current project. I am making a replica of Minesweeper. I want the 256 (16x16) tiles of the board to be created dynamically during the form load of the program. I use my own class for the tiles, which inherits the Button class because I need them to have some additional parameters. I have a two-dimensional array of that class and I use two nesting for...next statements to create all the elements in the array and then add them to the form controls so that they appear in the main window. However, instead of evenly spreading over the empty field to form a grid, they all appear in the lower-right corner on top of each other like this:
Attachment 95409
Here is the code I am using for the tiles:
How can I fix this?
Attachment 95409
Here is the code I am using for the tiles:
Code:
Public Class Tile
Inherits Button
Public mine, flag As Boolean
Public x, y As Integer
End Class
Dim tiles(20, 20) As Tile
Dim til As New Tile
Dim l, t As New Integer
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
l = 12
t = 114
For i = 1 To 16
For j = 1 To 16
til.x = i
til.y = j
til.Left = l
til.Top = t
til.Width = 32
til.Height = 32
til.FlatStyle = FlatStyle.Popup
til.Image = My.Resources.normaltile
til.mine = False
til.flag = False
tiles(i, j) = til
Me.Controls.Add(tiles(i, j))
l = l + 32
Next
l = 12
t = t + 32
Next
End Sub