可以在滚动条上绘画吗?
是否可以在 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
确实有可能,你可能想看一下
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 theWM_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 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.
(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
听起来您可以创建一个自定义控件(源自 TMemo 或其他控件)。您可以
覆盖
该控件的Paint
过程,如此处。我不知道这是否允许您在滚动条上绘图,但希望它可以帮助您创建自定义控件。
编辑
汤米的答案和我的答案的组合:这里是一个例子(虽然有点更复杂),它使用 WindowProc 方法来处理自定义控件中的消息。如果您创建一个控件,您也许能够处理
WM_NCPAINT
消息。另外这里是有关 Delphi 中 Windows 消息处理的更多信息。Sounds like you could create a custom control (deriving from TMemo or whatever). You could
override
thePaint
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 theWM_NCPAINT
message. Also here is some more info about Windows Message handling in Delphi.