How can I set the title color of VirtualStringTree?

The VirtualStringTree header has a "Background" property, but setting it to a different color does not change the color. I suspect the tree is displayed using windows themes.

How do I set the color?

0


source to share


2 answers


You can use the property THeader.Background

, but you must exclude toThemeAware

from TreeOptions.PaintOptions

. This would disable themes, as TLama already said in the comments.


I recommend that you use events OnAdvancedHeaderDraw

and OnHeaderDrawQueryElements

. hoOwnerDraw

must be turned on Header.Options

for them to take effect.



In OnHeaderDrawQueryElements

you installed Elements

in (at least) [hpeBackground]

, and in you OnAdvancedHeaderDraw

completed a custom drawing.

See this example ( 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;

      

+2


source


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;

      



0


source







All Articles