[英]Visual C# Loading Image from resource
我似乎無法從我的資源文件夾加載圖像,圖像根據組合框值而變化
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;
}
}
在解決方案資源管理器中,右鍵點擊你的項目名- >屬性- >添加現有文件...並選擇您需要的文件。 插入時,Visual Studio 將自動重命名資源圖像,用下划線替換空格、破折號、逗號,以便在您編寫Properties.Resources.
, IntelliSense 將向您顯示這些屬性的內容。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.