动态设置图像

时间:2013-02-05 23:28:25

标签: c# winforms embedded-resource picturebox

Image (pbAdvertisingSpace)picturebox属性中,我在Embedded Resources中添加了一些图片到我的项目中。

但是,我的困难是尝试动态设置pictureBox的图像,具体取决于另一个属性(HoleNumber)的值。从下面的试用方法中可以看出,

我尝试了几种不同的方式来改变图片,但到目前为止还没有成功。

有人可以告诉我访问这些图片的正确方法吗?

    private void SetAdvertisingLogo()
    {
        if (_getPlayerDetail.HoleNumber == 1 || _getPlayerDetail.HoleNumber == 8 || _getPlayerDetail.HoleNumber == 15)
        {
            pbAdvertisingSpace.Image.PropertyIdList.GetValue(7); 
        }
        else if (_getPlayerDetail.HoleNumber == 2 || _getPlayerDetail.HoleNumber == 9 || _getPlayerDetail.HoleNumber == 16)
        {
            pbAdvertisingSpace.Image.PropertyItems.ElementAt(9);
        }
        else if (_getPlayerDetail.HoleNumber == 3 || _getPlayerDetail.HoleNumber == 10 || _getPlayerDetail.HoleNumber == 17)
        {
            pbAdvertisingSpace.Image.PropertyItems.ElementAt(8);
        }
       etc...
    }

1 个答案:

答案 0 :(得分:1)

        pbAdvertisingSpace.Image = Resources.yourImage;