如何在 TVirtualDrawTree 中创建具有透明背景的节点?
我从 TVirtualDrawTree 派生一个自定义控件,并重写 DoPaintBackground
事件来为树视图绘制背景渐变效果。
我还重写了 DoBeforeItemPaint 函数,以便我可以自定义绘制树视图项。但是,我无法完全设法让项目以透明背景进行绘制。
查看 TVirtualDrawTree 的源代码,看起来好像该项目被复制到 TBitmap 图像,然后复制到画布上,但是,我尝试编辑源代码并在位图本身上设置透明度选项,但似乎仍然没有正在工作。
我还尝试在绘制之前清除画布,例如 Canvas.Brush.Style := bsClear
并填充项目矩形,但没有乐趣。
I am deriving a custom control from TVirtualDrawTree and I am overriding the DoPaintBackground
event to draw a background gradient effect for the tree view.
I am also overriding the DoBeforeItemPaint
function so I can custom draw the tree view items. However, I can't quite manage to get the items to paint with a transparent background.
Looking into the source for TVirtualDrawTree, it looks as though the item is copied to a TBitmap image and then copied onto the canvas, however, I have tried editing the source and setting the transparency options on the bitmap itself and it still doesn't seem to be working.
I have also tried clearing the canvas before drawing e.g. Canvas.Brush.Style := bsClear
and filling the item rect but no joy.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不做透明,作弊!
绘制渐变听起来需要大量工作:将其绘制到临时位图,这样您就不需要在每次调用 DoPaintBackgrdound() 时重新生成它。一旦您获得了位图中的背景,您就可以在处理
DoBeforeItemPaint
时将相关部分BitBlt
放入 Canvas 中,并且可以BitBlt
将位图当您需要整个背景时,整个虚拟树。这样您就不需要处理昂贵的透明度,但对于最终用户来说,您的物品看起来像是使用透明度绘制的。这是双赢的局面。
Don't do transparency, cheat!
Drawing the gradient sounds like a lot of work: draw it to a temporary bitmap so you don't need to re-generate it every time
DoPaintBackgrdound()
is called. Once you have the background in a bitmap you canBitBlt
the relevant portion into the Canvas when you handleDoBeforeItemPaint
, and you canBitBlt
the bitmap to the whole virtual tree when you need the whole background.This way you don't need to deal with expensive transparency yet for the end user it looks like your items had been painted using transparency. It's a win:win situation.