如何设置VirtualStringTree标头的颜色? [英] How to set the color of VirtualStringTree header?
问题描述
VirtualStringTree标头具有背景"属性,但将其设置为其他颜色不会更改颜色.我怀疑这棵树是使用Windows主题渲染的.
The VirtualStringTree header has a 'Background' property but setting it to a different color does not change the color. I suspect the tree is rendered using Windows themes.
如何设置颜色?
推荐答案
您可以使用属性THeader.Background
,但必须从TreeOptions.PaintOptions
中排除toThemeAware
.正如TLama在上面的评论中所说的那样,这将关闭主题.
You can use property THeader.Background
but you'll have to exclude toThemeAware
from TreeOptions.PaintOptions
. That would turn off themes, as TLama already said in his comment above.
我建议您使用事件OnAdvancedHeaderDraw
和OnHeaderDrawQueryElements
.要使它们生效,必须将hoOwnerDraw
包含在Header.Options
中.
I recommend you to use the events OnAdvancedHeaderDraw
and OnHeaderDrawQueryElements
. hoOwnerDraw
has to be included in Header.Options
for them to take effect.
在OnHeaderDrawQueryElements
中,将Elements
设置为(至少)[hpeBackground]
,在OnAdvancedHeaderDraw
中,进行自定义绘图.
In OnHeaderDrawQueryElements
you set Elements
to (at least) [hpeBackground]
and in OnAdvancedHeaderDraw
you do the custom drawing.
请参见以下示例(源):
procedure TfrmMain.MyVSTHeaderDrawQueryElements(Sender: TVTHeader;
var PaintInfo: THeaderPaintInfo; var Elements: THeaderPaintElements);
begin
Elements := [hpeBackground];
end;
procedure TfrmMain.MyVSTAdvancedHeaderDraw(Sender: TVTHeader;
var PaintInfo: THeaderPaintInfo; const Elements: THeaderPaintElements);
begin
if hpeBackground in Elements then
begin
PaintInfo.TargetCanvas.Brush.Color := clFuchsia; // <-- your color here
if Assigned(PaintInfo.Column) then
DrawFrameControl(PaintInfo.TargetCanvas.Handle, PaintInfo.PaintRectangle, DFC_BUTTON, DFCS_FLAT or DFCS_ADJUSTRECT); // <-- I think, that this keeps the style of the header background, but I'm not sure about that
PaintInfo.TargetCanvas.FillRect(PaintInfo.PaintRectangle);
end;
end;
这篇关于如何设置VirtualStringTree标头的颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!