I'm making a map editor to make maps
Every tile is a picurebox. In the menu there is a command "New" wich will load all the default pics into the picturebozes, so you can make a new map
i created this for statement
dim i as integer
For i = 0 To 391
PictureBox(i).image = My.Resources.Image_default
Next i
But this doesn't work. There is something wrong with the PictureBox(i).image
Please help me. I'm using vb2005
Thanks in advance,
Radexxion

Need help with for and pictureboxes
Karsten Januszewski MSFT
Let's assume you have 10 picture boxes named PictureBox1, PictureBox2 etc.
First of all you need to create an array to hold the picture boxes.
Dim PictureBoxes(10) As PictureBoxThis actually creates an 11 element array, element 0 will be left empty unless you first picture box is called PictureBox0
Then you add each of your boxes to the array (or strictly speaking you add a reference to each box to the array)
For Each ctrl As Control In Me.Controls If TypeOf ctrl Is PictureBox ThenPictureBoxes(
CInt(Mid(ctrl.Name, 11))) = CType(ctrl, PictureBox) End If NextThen you can reference any of the boxes through the array, e.g. PictureBox8 is referenced by PictureBoxes(8).
For counter As Integer = 1 To 10PictureBoxes(counter).BackColor = Color.Yellow
NextThe thought occurs that you may wish to create a two dimensional array to reference the boxes as I presume they will be laid out in a rectangular format on screen. You could then use the array indeces to reference the map as X and Y co-ordinates.
Dave
Heatmeista
Nokas
Carpe Noctem
That code was in C#, but it's easy to translate to VB (I'm not very familiar with VB syntax
There is problems with making editors like you doing now, try answer this questions:
Jean-Marie Epitalon
"There is something wrong with the PictureBox(i).image" doesn't really give much idea of the problem you are having.
Have you created an Array called PictureBox. Have you added all your picture boxes to it. What error message are you getting.
Dave
Kasracer
You're right......
1
2 nope
3 don't know it yet, friend already did that, try to use his code as basic for mine
4 nope
5 you can make something solid, so player can't walk over it
I guess i really need to translate the C# code.....
Thanks.....
n_sateesh
The settings i changed:
tools / options / windows form designer
set layoutmode to snaptogrid, and showgrid to true
I just copy and paste the boxes
This is how i work
I hope this is what you want to know S.G.
Radexxion
Btw, thanks for your reply Dave
It was very usefull, and it works (of course) :P
Nova SS
micca
Typically to create map editor you need to create own control based on ScrollableControl, then override OnPaint() method and draw images by yourself:
for (int x = 0; x < 20; x++)
{
for (int y = 0; y < 30; y++)
{
e.Graphics.DrawImage(Map[x, y], x * CellSize.Width, y * CellSize.Height);
}
}
This sample draw 30 lines of 20 cells. Map is matrix with Image objects, CellSize is Size structure with size of one cell. Of course you need add here scrolling support code line and visibility check code line. This will work much faster than creating so many controls.
SUpton
A friend of mine created the same thing, but then with vb6
Because of that i know it will work and wont take a lot of CPU/Memory
By the way, the code you posted is a C/C++ and i'm using VB
David Bachy
Generally you will need create MapEditorControl, add new CustomControl (Ctrl+Shift+A), it will open in designer, press F7 to view code. There you will find Paint() method in which you will need to paint your map. Just add this line for now to see all works:
Next step is to drop MapEditorControl on MainForm. Build project, open MainForm in designer, then in Toolbox find MapEditorControl and drop on the form and set Dock = Fill in properties. You should see red ellipse.
If you want you may contact me with Messenger (see my profile) so I can help you.
WoZoI
It says: Picurebox is a type and cannot be used as an expresion
I don't know exactly what an array is, so i guess i don't have one.
And adding all my picboxes to it will take a lot of time, there are almost 400 picboxes
I hope you can help me now,
Radexxion
David Homer
It's not so hard to create own control, draw there own map (including multiple layers and lines across cells) and handle mouse events. If you need - I can help, but all my samples in C#
derryckjw
I guess it's not difficult
Can you plz post some usefull codes with description, so i can make a mapeditor and learn C#
Thanks in forward,
Radexxion