如何设置VirtualStringTree标题的颜色?
VirtualStringTree标题具有“背景”属性,但将其设置为不同的颜色不会更改颜色。我怀疑树是使用Windows主题渲染的。如何设置VirtualStringTree标题的颜色?
如何设置颜色?
您可以使用属性THeader.Background
,但您必须从TreeOptions.PaintOptions
排除toThemeAware
。这会关闭主题,正如TLama在他上面的评论中所说的那样。
我建议你使用的事件OnAdvancedHeaderDraw
和OnHeaderDrawQueryElements
。必须包含在Header.Options
中才能生效。 (至少)[hpeBackground]
和OnAdvancedHeaderDraw
您自定义绘图。
参见该示例(source):
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;
如果未将Assigned(PaintInfo.Column)then语句添加到查询元素事件中,则最好添加。 'hpeBackground'元素也用于绘图板。在绘图事件中只需填充矩形。 – TLama
@TLama你的意思是“盘子”是什么意思? –
很好的回答!代码是最终的时候我会接受它。 –
procedure TfrmDepositDefrayalSingly.vstItemsManuallyHeaderDrawQueryElements(Sender: TVTHeader;
var PaintInfo: THeaderPaintInfo; var Elements: THeaderPaintElements);
begin
Elements := [hpeBackground];
end;
procedure TfrmDepositDefrayalSingly.vstItemsManuallyAdvancedHeaderDraw(Sender: TVTHeader;
var PaintInfo: THeaderPaintInfo; const Elements: THeaderPaintElements);
begin
if hpeBackground in Elements then
begin
PaintInfo.TargetCanvas.Brush.Color := cGlobalVar.BasicColor;
PaintInfo.TargetCanvas.FillRect(PaintInfo.PaintRectangle);
if Assigned(PaintInfo.Column) then
begin
PaintInfo.TargetCanvas.Brush.Color := clGray;
PaintInfo.TargetCanvas.FrameRect(PaintInfo.PaintRectangle);
end;
end;
end;
该属性被用于报头的背景下,对于不板。而且您必须关闭控件的主题(从'TreeOptions.PaintOptions'中排除'toThemeAware')。你所要求的听起来更像是自定义绘图的任务。你想要画什么(一个图像会是理想的)? – TLama
关闭ThemeAware不是一种选择,因为它不再平坦。我只需要一个较暗的灰色作为标题背景色... –
[喜欢这个](http://i.imgur.com/xevOLcX.png)?请注意,背景在该图片上没有渐变。该渐变需要一些额外的工作。 – TLama