tags:

views:

42

answers:

1

Hello,

In theory the whole thing I'm trying to accomplish is stupid from object orientated point of view,but I have to do it.

Its an Online game I'm working on.The client has an inventory with items,you know - virtual items. The server sends the items with their corresponding position in the inventory.

This is how my inventory looks like:

I have 62 panels(each panel represents the room in the inventory).

My problem:When I sort out the virtual items and the corresponding slots they should be placed in,I have to draw them on form.

In theory,If I receive item "C:\a.bmp" in position 4,how do I set panel4.image to be equal to the image?

This is what I'm trying to do:

var data = new byte[6];
... //we receive a packet,data is our buffer
var position = data[4];
Form1.panel + position + .backgroundImage = "bla bla.jpg";

How do call the panels like that?

+2  A: 

Turn them into an array instead of having 62 individual variables. Then you can use:

Form1.panels[position].BackgroundImage = "...";

There isn't any designer support for this (that I'm aware of) though - did you create all those panels in the designer? If you can possibly do it programmatically instead, you'll make your life a lot easier (IMO).

Jon Skeet
They always told me this and I always forget this tiny solution.Thanks again Jon!
John
Should I create another array and add them by hand or should I edit the Designer.cs? I never tried to do this before.
John
d'oh, I'm too slow again.
Robert
I would personally remove them from the designer, and add them in your code. If you've got that many panels, is there some formula for working out the size and location of most of them? (For instance, is it basically a grid?) If so, that should make things a lot easier.
Jon Skeet