简体   繁体   中英

How to change picture in picturebox according to value in combobox

I would like to ask you, how can I change picture in picture box, according to value in combobox. For example, I would like to have picture of "dog" when I choose in combobox "dog", when I change in combobox to "cat",in picturebox I will have cat. Thank you

If you want to change the image in picture box according to value in combobox, you can refer to the following code:

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (comboBox1.SelectedIndex == 0)
        {
            pictureBox1.Image = Image.FromFile(@"Image1 path");
        }
        else if (comboBox1.SelectedIndex == 1)
        {
            pictureBox1.Image = Image.FromFile(@"Image2 path");
        }
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM