Einzelnen Beitrag anzeigen

LoZe

Registriert seit: 27. Dez 2016
Ort: Ulm
40 Beiträge
 
Delphi 12 Athens
 
#4

AW: TTreeView.CustomDraw

  Alt 22. Apr 2022, 06:34
Hallo, So vielleicht? (ungetestet)

Delphi-Quellcode:
procedure TForm1.TreeViewCustomDrawItem(Sender: TCustomTreeView; Node: TTreeNode; State: TCustomDrawState; var DefaultDraw: Boolean);
var
  Tree:TTreeView;
  BG:TRect;
  TR:TRect;
  Box:TRect;
  txt:String;
begin
  Tree:= Sender as TTreeView;
  BG:= Node.DisplayRect(true);
  TR:= Rect(BG.Left + BG.Height + 4, BG.Top,BG.Right,BG.Bottom);
  Box:= Rect(BG.Left,bg.Top,BG.Left + BG.Height,bg.Bottom);

  Txt:= Node.Text;

  with Tree.Canvas do
  begin
    if cdsSelected in State then
    begin
      Brush.Color:= clHighlight;
      Font.Color:= clHighlightText;
    end
    else
    begin
      Brush.Color:= clWindow;
      Font.Color:= clWindowText;
    end;
    FillRect(BG);
    TextRect(TR,Txt,[tfVerticalCenter,tfSingleLine]);
   
    if Txt = '1then
    begin
        Brush.Color:= clRed;
        FillRect(Box);
    end;
    if Txt = '2then
    begin
        Brush.Color:= clLime;
        FillRect(Box);
    end;
  end;
end;
Chris

Geändert von LoZe (22. Apr 2022 um 06:41 Uhr)
  Mit Zitat antworten Zitat