In your form I am assuimg you have a combo box called comboBox1 and a image control called countryImageBox next to the combo box -
Given that you have the flag files in bin folder and in your combo box you have the country name or the file name, you can do like this:
namespace CountryList
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
comboBox1.Items.Add(new ListItem() { Name = "Australia", FlagName = "as.gif" });
comboBox1.Items.Add(new ListItem() { Name = "England", FlagName = "england.gif" });
comboBox1.Items.Add(new ListItem() { Name = "US", FlagName = "us-s.gif" });
comboBox1.DisplayMember = "Name";
comboBox1.ValueMember = "Name";
comboBox1.SelectedIndexChanged += new EventHandler(comboBox1_SelectedIndexChanged);
}
void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
if (comboBox1.SelectedItem != null)
{
this.countryImageBox.Image = Image.FromFile(((ListItem)comboBox1.SelectedItem).FlagName);
}
}
}
public class ListItem
{
public string Name { get; set; }
public string FlagName { get; set; }
}
}
The code is very simple, basically on selectedIndex change event of the combo box we find out what is the item selected and it's related flag file name. Then we just display image from that file.