How do I set the value as an icon?

I have a problem. First, I'll show you a little piece of code from my Minesweeper game I'm making.

lbl_grid[mineX, mineY].Text = "*";

      

Now, what it does is it sets a mine in my mesh to look like *

.

Instead, I want an lbl_grid[mineX, mineY].Text

icon value assigned to. Is it possible?

I believe I might have to use something other than text as icons are not text.

+3


source to share


1 answer


You are correct, you will need to use something other than text.

The option is to create a 2D array of PictureBox.

int rows = 3;
int cols = 4;

List<List<PictureBox>> pictures = new List<List<PictureBox>>();

for(int r = 0; r < rows; r++)
{
    List<PictureBox> pList = new List<PictureBox>();
    for(int c = 0; c < cols; c++)
    {
        //do any positioning you need to do here
        pList.Add(new PictureBox());
    }
    pictures.Add(pList);
}

      



Then you can access and set the source of the image.

pictures[rVal][cVal].Image = Image.FromFile("<file path>");

      

+1


source







All Articles