C#用下拉框选择对象让pictureBox显示对象图片,其中用到ImageList控件存储图片

如何让下拉框选择哪个对象,pictureBox就显示相应的对象图片?效果图如下

这里用到了三个控件,comboBox1、pictureBox1和imageList1。话不多少,上代码!

comboBox1 && pictureBox1

//选择不同对象
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
int index = comboBox1.SelectedIndex;
obType = index;
comboBox1.Text = comboBox1.Items[obType].ToString();
this.pictureBox1.Image = this.imageList1.Images[obType];
Console.WriteLine(comboBox1.Text);
}

点击ImageList的属性窗口,在集合编辑器添加图片,其中主要图片顺序和下拉框对象名字应该一致。

posted @ 2022-09-13 11:09  Margaretter  阅读(460)  评论(0)    收藏  举报