c# - Visual C# 从资源加载图像
问题描述
我似乎无法从我的资源文件夹中加载图像,图像会根据组合框的值而变化
if(cmbProduct.Text == "T-Shirt, Black, The Big Day Out" ||
cmbProduct.Text == "T-Shirt, Black, V-Vestival" ||
cmbProduct.Text == "T-Shirt, Black, Sound Relief")
{
picProduct.Visible = true;
picProduct.Image = Image.FromFile("T-Shirt, Black.jpeg");
}
解决方案
@Felix D 提到的是将您的图像作为“现有文件”添加到资源中。不过,“ T-Shirt, Black.jpeg ”的名称将T_Shirt__Black
在资源中重命名为。
我相信以下是您可能想要实现的目标:-
private void cmbProduct_SelectedIndexChanged(object sender, EventArgs e)
{
picProduct.Visible = false;
picProduct.InitialImage = null;
if (cmbProduct.Text == "T-Shirt, Black, The Big Day Out" || cmbProduct.Text == "T-Shirt, Black, V-Vestival" || cmbProduct.Text == "T-Shirt, Black, Sound Relief")
{
picProduct.Visible = true;
picProduct.Image = Properties.Resources.T_Shirt__Black;
}
}
在解决方案资源管理器中,右键单击您的projectName --> Properties --> Add Existing File... 并选择所需的文件。在插入时,Visual Studio 将自动重命名资源图像,用下划线替换空格、破折号、逗号,因此当您编写 时Properties.Resources.
,IntelliSense 将显示属性具有的内容。
推荐阅读
- java - MVC:模型或控制器/视图中的坐标和形状方法?
- css - 如何在带有ruby on rails的伪元素中显示来自svg sprite的图标
- laravel - 发生错误:ArtisanLambdaFunction - 解压后的大小必须小于 220606645 字节(服务:Lambda,状态码:4000
- mongodb - 如何使用 mongodb 在环回 4 中实现 groupBy?
- react-native - 从图库中获取图像的 url 并将图像从设备转换为 tensor3d
- git - 如果不存在标签,则获取第一次提交
- java - Android Studio (Windows) 中的 Flutter 错误:无法识别的选项:--add-opens
- reactjs - 如何使用 Storybook 制作别名?
- django - 通用 DeleteView 在 0x04725628 返回 django.db.models.query_utils.DeferredAttribute 对象 - Django
- microsoft-graph-api - ms botframework 附件无法生成共享链接