Click here to Skip to main content
15,908,020 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
M using SQL Server(Database).

i have a combobox on my Windows Application Form so when a user select a country like South Afrika, the flag must apper on a Form.

The Images file is on a bin .

Please help i don't have any idea and i have to submit this project
Posted

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:

C#
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.
 
Share this answer
 
hope this helps

C#
private void button1_Click(object sender, EventArgs e)
       {
           openFileDialog1.ShowDialog();
           Image image = Image.FromFile(openFileDialog1.FileName);
           // Set the PictureBox image property to this image.
           // ... Then, adjust its height and width properties.
           pictureBox1.Image = image;
           pictureBox1.Height = image.Height;
           pictureBox1.Width = image.Width;
       }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900