Valhalla Legends Forums Archive | Visual Basic Programming | [.net] Dynamic Picture Box Array

AuthorMessageTime
Imperceptus
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.

[code]   
    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[/code]

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?
August 25, 2007, 8:36 PM
Barabajagal
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
August 25, 2007, 9:01 PM
Myndfyr
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:
[code]
controlToWhichToAddThisPicturebox.Controls.Add(m(x, y))
[/code]

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?
August 26, 2007, 8:01 AM
Imperceptus
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.
August 26, 2007, 7:18 PM
Imperceptus
Yes. that was what I needed. Thanks a ton man. 

[code]    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[/code]
August 26, 2007, 7:21 PM

Search