我如何添加圖像(特定圖像)轉換成列表視圖與foreach語句 例如:C#ListView項圖片
foreach(Video entry in videoFeed.Entries) {
listview1.items.add(entry);
listview1.items.image(imageURL);
}
我如何添加圖像(特定圖像)轉換成列表視圖與foreach語句 例如:C#ListView項圖片
foreach(Video entry in videoFeed.Entries) {
listview1.items.add(entry);
listview1.items.image(imageURL);
}
如果你想要的是顯示圖像爲您ListViewItem的,那麼你需要創建一個的ImageList,用圖像填充它,在的ImageList分配給的ListView,然後告訴每一ListViewItem的要使用的圖像從列表:
var listView = new ListView();
// create image list and fill it
var imageList = new ImageList();
imageList.Images.Add("itemImageKey", image);
// tell your ListView to use the new image list
listView.LargeImageList = imageList;
// add an item
var listViewItem = listView.Items.Add("Item with image");
// and tell the item which image to use
listViewItem.ImageKey = "itemImageKey";
您可以閱讀更多關於ListViewItem以及如何設置/使用MSDN article或MSDN tutorial中的圖像。
private void Form1_Load(object sender, EventArgs e)
{
List<string> adress = new List<string>(){"http://www.diseno-art.com/news_content/wp-content/uploads/2012/09/2013-Jaguar-F-Type-1-600x399.jpg"
,"http://i.telegraph.co.uk/multimedia/archive/02351/Jaguar-F-type-9_2351861k.jpg",
"http://i.telegraph.co.uk/multimedia/archive/02351/Jaguar-F-type-5_2351885k.jpg",
"http://i.telegraph.co.uk/multimedia/archive/02351/Jaguar-F-type-7_2351893k.jpg"};
ImageList il = new ImageList();
foreach (string img in adress)
{
System.Net.WebRequest request = System.Net.WebRequest.Create(img);
System.Net.WebResponse resp = request.GetResponse();
System.IO.Stream respStream = resp.GetResponseStream();
Bitmap bmp = new Bitmap(respStream);
respStream.Dispose();
il.Images.Add(bmp);
}
il.ImageSize = new Size(32, 32);
int count = 0;
listView1.LargeImageList = il;
List<string> names = new List<string>(){"1","2","3","4"};
foreach (string s in names)
{
ListViewItem lst = new ListViewItem();
lst.Text = s;
lst.ImageIndex = count++;
listView1.Items.Add(lst);
}
}
這是給你不給每個圖像複製manualy到您的計算機,而不是您所提供的網址,並把該圖像在一個新的位圖,並添加到列表中
ASP.NET,WPF的一個選項, ....? – Tim
只c犀利,表示 –