On a treeview after the select event, I populate a listview with images.
I want to custom format these images and place a black color border around each image.
private void TreeView1_Select(object sender, EventArgs e) {
if (folder != null && System.IO.Directory.Exists(folder)) {
DirectoryInfo dir = new DirectoryInfo(@folder);
foreach (FileInfo file in dir.GetFiles()) {
try {
imageList.Images.Add(Image.FromFile(file.FullName));
} catch {
Console.WriteLine("This is not an image file");
}
}
for (int j = 0; j < imageList.Images.Count; j++) {
this.ListView1.Items.Add("Item" + j);
this.ListView1.Items[j].ImageIndex = j;
}
this.ListView1.View = View.LargeIcon;
this.ListView1.LargeImageList = imageList;
this.ListView1.DrawItem +=
new DrawListViewItemEventHandler(ListView1_DrawItem);
}
}
private void ListView1_DrawItem(object sender, DrawListViewItemEventArgs e)
{
}
I would add a border using a
Graphics
object immediately after loading the images from file:EDIT: modified the code, this works for me...
NOTE: the image copying is intended; if I modify the code to
as suggested in the comments, I get an exception saying "A Graphics object cannot be created from an image that has an indexed pixel format."