如何设置VirtualStringTree标头的颜色? [英] How to set the color of VirtualStringTree header?

查看:187
本文介绍了如何设置VirtualStringTree标头的颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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.

我建议您使用事件OnAdvancedHeaderDrawOnHeaderDrawQueryElements.要使它们生效,必须将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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆