試圖爲資源文件夾中的圖像生成文件名,並顯示它屁股錯誤。 我創建文件名到字符串參數, 已經創建btn作爲按鈕'尋找「文件名」參數。 錯誤是:錯誤1'warCards.Properties.Resources'不包含'文件名'的定義。 遊戲:戰爭(紙牌遊戲) 感謝助理爲圖像構建文件名稱作爲資源C#
btn.Click += delegate(object sender, EventArgs e)
{
Random rnd = new Random();
int num = rnd.Next(1, 14);
int letter = 0;// represent random cards symbol 1-dimond 2-heart 3-spades 4-clubs
string fileName = "_";
if (num < 10 && num > 1)
{
fileName = fileName + "0" + num.ToString() + "_of_";
if (isBlack)
{
letter = rnd.Next(1, 3);
if (letter == 1)
{
fileName += "spades";
}
else
{
fileName += "clubs";
}
//for example: try to create: _5_of_spades
btn.BackgroundImage = warCards.Properties.Resources.fileName;
btn.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
btn.Enabled = false;
isBlack = !isBlack;
}
}
};
this.Controls.Add(btn);
nextPos.X += 112;
};
'int letter = 0;'lol ;-) –
使用[''Assembly.GetEntryAssembly().GetManifestResourceNames()'](https://msdn.microsoft.com/en-us/library /system.reflection.assembly.getmanifestresourcenames(v=vs.110).aspx)檢查資源的完整名稱並使用['Assembly.GetEntryAssembly()。GetManifestResourceStream(string name)'](https:// msdn。 microsoft.com/en-us/library/xc4235zt(v=vs.110).aspx)來獲取位圖流,(你可以加載如果從一個流) –
我應該使用這個命令? 。在資源文件夾上的圖片是png –