我有1個圖片框,名爲studPic
。我想得到的是,當我點擊「隨機播放」按鈕時,從資源中獲取隨機圖像。從按鈕點擊資源中隨機播放隨機圖片
private void button2_Click(object sender, EventArgs e)
{
...
}
研究之後,我發現以下
我新手,C#..有更簡單的方法來實現這一結果?例如,不添加圖片名稱?
UPDATE
List<string> pictureNames = new List<string>();
pictureNames.Add("1");
pictureNames.Add("2");
pictureNames.Add("3");
int randomPictureIndex = new Random().Next(0, pictureNames.Count);
string randomPictureName = pictureNames[randomPictureIndex];
pictureNames.Remove(randomPictureName);
Image img = Properties.Resources.randomPictureName; //erroor
studPic.Image = img;
收到錯誤消息 錯誤1 'Properties.Resources' 不包含定義 'randomPictureName'
什麼是你的資源? –
@ChrisGessler應用程序資源 – heron
@ChrisGessler已更新。請看看 – heron