How do you access the name of the image in a picturebox in Visual Studio using C#

前端 未结 4 1524
花落未央
花落未央 2020-12-12 02:35

I have a program which has 16 grid tiles using picturebox but only uses 5 images, the rest of the tiles are just a black image.

I would like to be able to tell which

4条回答
  •  生来不讨喜
    2020-12-12 03:17

    Use PictureBox.Load(string) method to load images from file. Then the file path will be stored in the PictureBox.ImageLocation property:

    A call to the Load method will overwrite the ImageLocation property, setting ImageLocation to the URL value specified in the method call.

    So you can write for example:

    if (peckedSquare.ImageLocation.EndsWith("pigeon1.png"))
    {
        System.Diagnostics.Debug.WriteLine("Pecked Pigeon number 1");
    }
    

提交回复
热议问题