最も簡単な方法の1つは、名前と画像の両方をList<KeyValuePair<string,Image>>
またはIDictionary<string,image>
に保存することです。ここで
はIDictionary<string,image>
を使用した例です(私があるため、インデックスのSortedList<>
に決定):List<KeyValuePair<string,Image>>
用
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];
は次のようになります。
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;
あなたの画像はすべて「Properties.Resources'からですか?それは単なる例ですか? – digEmAll
これはちょっとした例です。もし私がそれを試すことができる代替案があれば。私はちょうど写真の名前を書く。 – nevra
私は自分の答えで言ったように、あなたは名前と画像の両方を保存することができます。しかしおそらく、あなたがこのようなアプローチが可能かどうかを理解するために、画像のソースを指定するべきでしょう。 – digEmAll