我正在尝试在 Richtextbox 中构建类似文件列表的树视图。
它应该看起来像一个资源管理器树视图。我的代码能够调整图标大小,但缺少透明度(浅灰色背景而不是透明度)。我需要在这里改变什么?是不是图片格式不对?
有没有更好的方法将图像添加到 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();
Example:
Edit:
我发现图像是透明的,但使用 Clipboard.SetImage() 不会将其发布为透明图像。
有什么想法为什么以及我能做什么来解决它吗?我需要切换到不同的文本框控件吗?