如何自定义滚动条颜色? [英] How to customize a scrollbar color?
本文介绍了如何自定义滚动条颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我发现了以下示例代码,用于尝试自定义滚动条颜色:
I found some sample code like below, for trying to customize a scrollbar color:
HBRUSH CMainFrame::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CFrameWnd::OnCtlColor(pDC, pWnd, nCtlColor);
if(nCtlColor==CTLCOLOR_SCROLLBAR)
return m_brColor;
return hbr;
}
我发现以下代码不起作用:
I found that the following code does not work:
procedure TForm1.WMCTLColor(var msg: TWMCTLCOLOR); message WM_CTLCOLOR;
我该如何在Delphi中做到这一点?
How can I do it in Delphi?
推荐答案
本机api中没有WM_CTLCOLOR
消息.相反,您可以使用CN_CTLCOLORSCROLLBAR
控件通知,该通知由VCL发送到子控件,以响应API的
There's no WM_CTLCOLOR
message in the native api. Instead you can use CN_CTLCOLORSCROLLBAR
control notification, which is send to child controls by the VCL in response to the API's WM_CTLCOLORSCROLLBAR
.
type
TScrollBar = class(TScrollBar)
protected
procedure WMCtlColor(var Message: TWMCtlColorScrollbar); message CN_CTLCOLORSCROLLBAR;
end;
procedure TScrollBar.WMCtlColor(var Message: TWMCtlColor);
begin
Message.Result := CreateSolidBrush(RGB(255, 255, 0));
end;
或者,如果您不想派生新控件,则将滚动条放置在表单上:
Or, if you don't want to derive a new control, provided the scrollbar is placed on the form:
TForm1 = class(TForm)
...
protected
procedure WMCtlColorScrollbar(var Message: TWMCtlColorScrollbar);
message WM_CTLCOLORSCROLLBAR;
...
end;
procedure TForm1.WMCtlColorScrollbar(var Message: TWMCtlColorScrollbar);
begin
if Message.ChildWnd = ScrollBar1.Handle then
Message.Result := CreateSolidBrush(RGB(255, 255, 0));
end;
这篇关于如何自定义滚动条颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文