可以在滚动条上绘画吗?

发布于 2024-08-20 23:36:39 字数 109 浏览 9 评论 0原文

是否可以在 TMemo、TListbox 等标准控件的滚动条上进行绘制?

我所需要的只是在滚动条上绘制一些基本形状,并且我试图避免从 stratch 实现整个滚动内容。有什么指点吗?蒂亚!

Is it possible to paint on the scrollbars of standart controls like TMemo, TListbox, etc..?

All I need is to draw some basic shapes on the scrollbars and I'm trying to avoid implementing whole scrolling stuff from stratch. Any pointers? TIA!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

七禾 2024-08-27 23:36:39

确实有可能,你可能想看一下WM_NCPAINT消息,这是WM_PAINT消息的非客户区对应版本。这不是一件容易的任务,但是由于您不打算自己绘制整个滚动条,因此可能会更直接。

此外,您可能会发现这个文章 [1] 来自 代码项目 有趣,代码是 C++ 语言,格式不完全正确,但它应该给出一些关于如何实现滚动条的所有者绘制的想法。

代码项目的屏幕截图
来自前面提到的 TCP 项目的屏幕截图。

除了第一个项目之外,您可能会发现 这个项目 [2] 有趣,它还拥有绘制滚动条,我知道您只想在滚动条顶部绘制,但我敢打赌是这也会对您有所帮助,它也包含源代码。

屏幕截图酷滚动条项目
(来源:catch22.net

屏幕截图来自 Cool Scrollbar 项目。

检查 VCL 源代码可能有助于检索有关滚动条按钮位置等的信息。代码可以在 forms.pas 文件中找到,至少它是这样的从我的简短搜索看来。希望以上内容对您有所帮助。祝你好运。

更新了链接,很酷的滚动条页面似乎已关闭,所以我链接到存档版本

[1] https://www.codeproject.com/Articles/14724/Replace-a-Window-s-Internal-Scrollbar-与客户
[2] https://web .archive.org/web/20170924110426/http://www.catch22.net/tuts/custom-scrollbars

It is indeed possible, you might want to take a look at the WM_NCPAINT message, this is the non-client area corresponding version of the WM_PAINT message. This is not an easy task, however since you are not about to do the entire scrollbar drawing yourself it might be more straight forward.

Further more you might find this article [1] from The Code Project interesting, the code is in C++ and not entirely well formatted, but it should give some idea as to how one could achieve ownerdrawing of scrollbars.

Screenshot from project at The Code Project
Screenshot from the previous mentioned project at TCP.

Besides the first project you might find this project [2] interesting, it also ownerdraws the scrollbar, I'm aware that you only want to draw on top of the scrollbar but my bet is that this will help you as well, it includes source code as well.

Screenshot from Cool Scrollbar project
(source: catch22.net)

Screenshot from the Cool Scrollbar project.

It might help to examine the VCL Source code in order to retrieve information on position of the scroll bar buttons etc. The code can be found in the forms.pas file, at least that's what it seemed like from my brief search. Hope any of this can be of any help. Good luck.

Updated links, the cool scrollbar page seems to be down, so I have linked to the archived version

[1] https://www.codeproject.com/Articles/14724/Replace-a-Window-s-Internal-Scrollbar-with-a-custo
[2] https://web.archive.org/web/20170924110426/http://www.catch22.net/tuts/custom-scrollbars

雨后咖啡店 2024-08-27 23:36:39

听起来您可以创建一个自定义控件(源自 TMemo 或其他控件)。您可以覆盖该控件的Paint过程,如此处

我不知道这是否允许您在滚动条上绘图,但希望它可以帮助您创建自定义控件。

编辑
汤米的答案和我的答案的组合:这里是一个例子(虽然有点更复杂),它使用 WindowProc 方法来处理自定义控件中的消息。如果您创建一个控件,您也许能够处理 WM_NCPAINT 消息。另外这里是有关 Delphi 中 Windows 消息处理的更多信息。

Sounds like you could create a custom control (deriving from TMemo or whatever). You could override the Paint procedure of that control as described here.

I don't know if that will allow you draw on the scrollbars but hopefully it helps you in creating a custom control.

EDIT
A combonation of Tommy's answer and mine: Here is an example (albeit a bit more complex) that uses the WindowProc method to handle messages in a custom control. If you create a control you maybe able to handle the WM_NCPAINT message. Also here is some more info about Windows Message handling in Delphi.

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