好吧,最简单的方法之一是将名称和图像保存在 a List<KeyValuePair<string,Image>>
orIDictionary<string,image>
中。
这是一个使用 a 的示例IDictionary<string,image>
(我SortedList<>
因为索引而决定):
var images = new SortedList<string, Image>();
images.Add("baseball_bat", Properties.Resources.baseball_bat);
images.Add("bracelet", Properties.Resources.bracelet);
...
// when you show the first image...
pictureBox1.Image = images.Values[0];
textBox1.Text = images.Keys[0];
// when you show the nth image...
pictureBox1.Image = images.Values[n];
textBox1.Text = images.Keys[n];
对于 aList<KeyValuePair<string,Image>>
将是:
var images = new List<KeyValuePair<string, Image>>();
images.Add(new KeyValuePair<string,Image>("baseball_bat", Properties.Resources.baseball_bat));
images.Add(new KeyValuePair<string,Image>("bracelet", Properties.Resources.bracelet));
...
// when you show the first image...
pictureBox1.Image = images[0].Values;
textBox1.Text = images[0].Keys;
// when you show the nth image...
pictureBox1.Image = images[n].Values;
textBox1.Text = images[n].Keys;