我使用此代码来检查背景图片:帮助检查的BackgroundImage
if (actionbox1.BackgroundImage == "WaterforMGC.strollinstu.png")
但我得到的错误操作符“==”不能应用于类型“为System.Drawing.Image”和“字符串操作数'
那么如何检查BackgroundImage属性?
以防万一,这里是我的随机化代码:
//actionbox1
var imageNames = new List<string> { "WaterforMGC.strollinstu.png", "WaterforMGC.blank.png", "WaterforMGC.swoopinstu.png", "WaterforMGC.waterbottle.png", "WaterforMGC.goop.png", "WaterforMGC.blank.png" };
var rand = new Random();
var index = rand.Next(0, imageNames.Count - 1);
var s = this.GetType().Assembly.GetManifestResourceStream(imageNames[index]);
actionbox1.BackgroundImage = Image.FromStream(s);
您无法将字符串与图像进行比较。您必须保存已加载的图像的路径,以便比较两个字符串,或者首先加载路径指向的图像,以便比较两个图像。 –