我使用此代碼來檢查背景圖片:幫助檢查的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);
您無法將字符串與圖像進行比較。您必須保存已加載的圖像的路徑,以便比較兩個字符串,或者首先加載路徑指向的圖像,以便比較兩個圖像。 –