我试图在richtext框中构建一个像树形视图文件列表。图标图像 - 透明度问题
它应该看起来像一个资源管理器树视图。我的代码能够调整图标的大小,但缺少透明度(浅灰色背景而不是透明度)。我需要在这里更改什么?图像格式是否错误? 有没有更好的方式将图像添加到richtextbox?
// Get file info
FileInfo f = new FileInfo("myfile.name");
// Get icon for fileinfo
Icon ico = Icon.ExtractAssociatedIcon(f);
// Convert icon to bitmap
Bitmap bm = ico.ToBitmap();
// create new image with desired size
Bitmap img = new Bitmap(16,16,PixelFormat.Frmat32bpRgb);
// Create graphics with desired sized image
Graphics g = Graphics.FormImage(img);
// set interpolation mode
g.InterpolationMode = InterpolationMode.HighQualityBiCubic;
// draw/resize image
g.DrawImage(bm, new Rectangle(0,0,16,16), new Rectangle(0, 0, bm.Width, bm,Height), GraphicalUnit.Pixel);
// Paste to clipboard
Clipboard.SetImage(bm);
// Paste in RichtextBox
rtb.Paste();
实施例:
编辑:
我已想出该图像是透明的,但使用Clipboard.SetImage()不发布为透明的图像。
任何想法为什么和我能做些什么来解决它?我是否需要切换到不同的文本框控件?
我不明白。为什么不实际使用TreeView? ImageList没有麻烦的图标。 – 2010-09-20 23:19:36
因为我需要打印它 - 如果我使用树视图,这是多个页面的问题......并且我使用imagelist作为缓存 - 这只是当前问题的一部分。 – 2010-09-21 22:54:48