I would add a border using a Graphics
object immediately after loading the images from file:
EDIT: modified the code, this works for me...
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()) {
Image img = new Bitmap(Image.FromFile(file.FullName));
using (Graphics g = Graphics.FromImage(img)){
g.DrawRectangle(Pens.Black, 0, 0, img.Width - 2, img.Height - 2);
}
imageList.Images.Add(img);
NOTE: the image copying is intended; if I modify the code to
Image img = (Bitmap)Bitmap.FromFile("test.bmp");
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."
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…