最も簡単な方法の 1 つは、名前と画像の両方をList<KeyValuePair<string,Image>>
またはに保存することIDictionary<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];
の場合は次のList<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;