Einzelnen Beitrag anzeigen

LoZe

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

AW: TTreeView.CustomDraw

  Alt 22. Apr 2022, 10:53
Delphi-Quellcode:
procedure TForm3.TreeView1AdvancedCustomDrawItem(Sender: TCustomTreeView; Node: TTreeNode; State: TCustomDrawState; Stage: TCustomDrawStage;
  var PaintImages, 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;
    // Nur Zeichnen wenn Eintrag Erkannt!!!
    if (pos('1',Txt) = 1) or (pos('2',Txt) = 1) then
    begin


      FillRect(BG);
      TextRect(TR,Txt,[tfVerticalCenter,tfSingleLine]);

      if pos('1',Txt) = 1 then
      begin
          Brush.Color:= clRed;
          FillRect(Box);
      end;
      if pos('2',Txt) = 1 then
      begin
          Brush.Color:= clLime;
          FillRect(Box);
      end;
    end;
  end;

end;
Miniaturansicht angehängter Grafiken
screenshot-2022-04-22-115210.jpg  
Chris
  Mit Zitat antworten Zitat