Reputation: 35522
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?
Upvotes: 0
Views: 66
Reputation: 1501626
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).
Upvotes: 2