1
我試圖在使用組合框下拉列表的圖片框中顯示圖片,該圖片填充了各種類型的書籍;網絡,編程,網絡。當用戶選擇特定的書籍時,將顯示書籍封面的圖片。我嘗試了一堆不同的方法,但似乎沒有任何工作。我有thisGenreComboBox_SelectedIndexChanged,所以我想這是一個if/else if語句的問題。以下是我一直在嘗試的方式,我確信它已經過時了。建議?非常感謝!在PictureBox中使用組合框下拉列表
//if ((string)thisGenreComboBox.SelectedItem == ("Networking"))
//if (thisGenreComboBox.Text == "Networking")
if (thisGenreComboBox.SelectedIndex == 1)
{
thisGenrePictureBox.Image = Image.FromFile(@"networkingcover.jpg");
}
* *編輯
下面是我終於想出了和完美的作品對我的需求。此外,我將它應用於ListBox並且工作正常。
switch (thisGenreComboBox.SelectedIndex)
{
case 0:
{
thisGenrePictureBox.ImageLocation = ("NetworkCover.jpg");
break;
}
case 1:
{
thisGenrePictureBox.ImageLocation = ("ProgramCover.jpg");
break;
}
case 2:
{
thisGenrePictureBox.ImageLocation = ("WebProgramCover.jpg");
break;
}
}
禮,感謝您的時間和精力在幫助我與我的問題。 – Heavy
@Heavy如果你點擊答案附近的複選標記將答案標記爲已接受,那將會很棒:) –