如何在 TVirtualDrawTree 中创建具有透明背景的节点?

发布于 2024-10-30 05:30:30 字数 350 浏览 1 评论 0原文

我从 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

偏爱自由 2024-11-06 05:30:30

不做透明,作弊!

绘制渐变听起来需要大量工作:将其绘制到临时位图,这样您就不需要在每次调用 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 can BitBlt the relevant portion into the Canvas when you handle DoBeforeItemPaint, and you can BitBlt 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文