试图为资源文件夹中的图像生成文件名,并显示它屁股错误。 我创建文件名到字符串参数, 已经创建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 –