日期:2014-05-18 浏览次数:21015 次
string pathstr = null; private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { string str = comboBox1.Text; switch (str) { case "图片": pathstr = Directory.GetCurrentDirectory() + @"\wulin"; break; case "背景": pathstr = Directory.GetCurrentDirectory() + @"\beijing"; break; default: pathstr = Directory.GetCurrentDirectory() + @"\default"; break; } } imageList1.ColorDepth = ColorDepth.Depth32Bit; imageList1.ImageSize = new Size(220, 220); for (int i = 0; i < 4; i++) { imageList1.Images.Add(Image.FromFile(Application.StartupPath+@"\\beijing\\" + (i + 1).ToString() + ".jpg")); listView1.LargeImageList = imageList1; listView1.Items.Add((i + 1).ToString()); listView1.Items[i].ImageIndex = i; }
p rivate void button1_Click(object sender, EventArgs e) { imageList1.ColorDepth = ColorDepth.Depth24Bit; imageList1.ImageSize = new Size(120, 120); for (int i = 0; i < 12; i++) { imageList1.Images.Add(Image.FromFile(Application.StartupPath + "\\"+(i+1).ToString()+".jpg")); listView1.LargeImageList = imageList1; listView1.Items.Add((i+1).ToString()); listView1.Items[i].ImageIndex = i; } } 但是不能实现自动查找ImageList图片的个数如Imagelist1.Image.Count,而且查找文件还要指定文件名才能查找