【发布时间】:2011-04-14 22:32:09
【问题描述】:
我正在尝试在富文本框中构建类似树视图的文件列表。
它应该看起来像一个资源管理器树视图。我的代码能够调整图标大小,但缺少透明度(浅灰色背景而不是透明度)。我需要在这里改变什么?图片格式错了吗? 有没有更好的方法将图像添加到富文本框?
// 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 可以轻松制作图标。
-
因为我需要打印它——如果我使用树视图,多页就会出现问题......而且我使用图像列表作为缓存——这只是当前问题的一部分。跨度>
标签: c# .net image icons transparency