【问题标题】:Link a variable to image name in windows forms [duplicate]将变量链接到Windows窗体中的图像名称[重复]
【发布时间】:2021-12-20 22:57:12
【问题描述】:

我想设置一个带有图像的图片框,但有一个整数将它链接在一起。
资源中的图片命名为picture_1、picture_2、picture_3
这就是我想要做的,但是,我得到一个错误:

imageNumber = 1;
image_position[0, 1].Image = Properties.Resources.picture_ + imageNumber;

我正在尝试将图片框设置为 picture_1 但得到这个:
错误 CS0117“资源”不包含“图片_”的定义

【问题讨论】:

  • 这里image_position[0, 1].Image = Properties.Resources.picture_ + imageNumber有错吗? Properties.Resources.picture_ 包含什么?是字符串变量吗?

标签: c#


【解决方案1】:

您可以尝试使用ResourceManager.GetObject 方法。它接受字符串名称:

image_position[0, 1].Image =
    (Image) Properties.Resources.ResourceManager.GetObject("picture_" + imageNumber);

【讨论】:

    猜你喜欢
    • 2013-07-24
    • 1970-01-01
    • 1970-01-01
    • 2021-01-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-24
    • 2015-04-10
    相关资源
    最近更新 更多