我正在尝试在富文本框中构建类似文件列表的树形视图。它应该看起来像资源管理器树形视图。我的代码可以获取并调整图标大小,但透明度缺失(浅灰色背景代替透明)。我需要在这里做什么更改?图片格式是否有误?是否有更好的方法将图像添加到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()将其发布为不透明图像。
有没有什么想法,我该如何解决?我需要切换到另一个文本框控件吗?