I want to create a grid of sorts using the PictureBox Control. I could do it in vb6. But in .net its giving me grief. Here is what I have so far.
Private Sub DrawMap()
Dim x As Byte = 0, y As Byte = 0, m(10,21) As PictureBox
For x = 1 To 10
For y = 1 To 21
m(x, y) = New PictureBox
m(x, y).Left = (Block.Width * x) + 10
m(x, y).Top = (Block.Height * y) + 10
m(x, y).BackColor = Black
m(x, y).Visible = True
Next
Next
End Sub
This if you try it, you will find doesn't work. I have tried a few other ways to this and still I get nothing that works. Any suggestions?
Didn't .net get rid of object arrays?
Edit: my mistake, they just confusticated them -.-
http://www.vb-helper.com/howto_net_declare_array_objects.html
Have you considered using a DataGridView control and simply using databinding?
The most apparent error that I'm seeing here is that you're not putting the control anywhere. Without additional information (such as, are you getting a compile-time or run-time error, and if it's run-time, is it that it's giving you an actual error or is it misbehaving), I can't say for sure.
However, I think within that inner look, you want the code:
controlToWhichToAddThisPicturebox.Controls.Add(m(x, y))
Note that controlToWhichToAddThisPicturebox can be any valid identifier to a given instance of an object derived from System.Windows.Forms.Control, including a Form object.
@Andy: as you continually spout hate about and remind us that you don't use .NET, why do you even bother trying to post about it?
Im trying to make a tetris kind of game. And while I am without a doubt sure that I will refactor, redo the gui or just start over. It is a learning process. I did make a nifty way to rotate pieces though =).
Thanks for the not myndfyre. I will try it out.
Yes. that was what I needed. Thanks a ton man.
Private Sub DrawMap()
Dim x As Byte = 0, y As Byte = 0, m(10, 21) As PictureBox
For x = 1 To 10
For y = 1 To 21
m(x, y) = New PictureBox
m(x, y).Left = (Block.Width * x) + 10
m(x, y).Top = (Block.Height * y) + 10
m(x, y).BackColor = Black
m(x, y).Visible = True
Me.Controls.Add(m(x, y))
Next
Next
End Sub