• Welcome to Valhalla Legends Archive.
 

[.net] Dynamic Picture Box Array

Started by Imperceptus, August 25, 2007, 03:36 PM

Previous topic - Next topic

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.

   
     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?
Quote from: Hazard on August 07, 2003, 03:15 PM
Highlight your entire code. Press the delete key. Start over again using Cuphead's CSB tutorial and work your way from their rather than raping code from downloaded sources meant purely for learning purposes. If this does not fix the problem, uninstall Visual Basic and get a new hobby. I suggest Cricket.

Barabajagal

#1
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

MyndFyre

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?
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

Imperceptus

#3
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.
Quote from: Hazard on August 07, 2003, 03:15 PM
Highlight your entire code. Press the delete key. Start over again using Cuphead's CSB tutorial and work your way from their rather than raping code from downloaded sources meant purely for learning purposes. If this does not fix the problem, uninstall Visual Basic and get a new hobby. I suggest Cricket.

Imperceptus

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
Quote from: Hazard on August 07, 2003, 03:15 PM
Highlight your entire code. Press the delete key. Start over again using Cuphead's CSB tutorial and work your way from their rather than raping code from downloaded sources meant purely for learning purposes. If this does not fix the problem, uninstall Visual Basic and get a new hobby. I suggest Cricket.