Board index » delphi » OnDrawItem

OnDrawItem

I need to code the OnDrawItem of a TOutline.  I need to do this so that
can draw on the canvas to allow me to change the canvas.font color of
particular TOutlineNodes.  I am successfull if I only have 1 level to the
outline.  If I addchild, it does not appear to draw like an outline
normally does.  Do I have to do all the code to draw the outline levels
with the proper parent?

here is what I am practicing with:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, Grids, Outline;

type
  TForm1 = class(TForm)
    Outline1: TOutline;
    BTN_FillOutline: TButton;
    BTN_Collapse: TButton;
    BTN_Expand: TButton;
    procedure BTN_FillOutlineClick(Sender: TObject);
    procedure Outline1DrawItem(Control: TWinControl; Index: Integer;
      Rect: TRect; State: TOwnerDrawState);
    procedure BTN_CollapseClick(Sender: TObject);
    procedure BTN_ExpandClick(Sender: TObject);
    procedure Outline1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  i : Pointer;

implementation

{$R *.DFM}

procedure TForm1.BTN_FillOutlineClick(Sender: TObject);
var
  x,j,k : Integer;
begin
  for x := 1 to 10 do
  begin
    j := Outline1.Add(0,'Node #' + inttostr(x));
    Outline1[j].Expand;
    k := Outline1.AddChild(j,'Node #' + IntToStr(x));
    Outline1[k].Data := @i;
    Outline1[k].Expand;
  end;
end;

procedure TForm1.Outline1DrawItem(Control: TWinControl; Index: Integer;
  Rect: TRect; State: TOwnerDrawState);
begin
  // draw on the control canvas, not on the form
  with (Control as TOutline).Canvas do
  begin

    // clear the rectangle
    FillRect(Rect);
    if Outline1[index + 1].Data = @i then
      Outline1.Canvas.Font.Color := clRed
    else
      Outline1.Canvas.Font.Color := clBlack;

    // display the text
    case Outline1[index + 1].Level of
      1 : TextOut(Rect.Left, Rect.Top, Outline1[index + 1].Text);
      2 : TextOut(Rect.Left + 15, Rect.Top, Outline1[index + 1].Text);
    end;
  end;
end;

procedure TForm1.BTN_ExpandClick(Sender: TObject);
begin
  Outline1.FullExpand;
end;

procedure TForm1.BTN_CollapseClick(Sender: TObject);
begin
  Outline1.FullCollapse;
end;

procedure TForm1.Outline1Click(Sender: TObject);
begin
  ShowMessage(IntToStr(Outline1.Items[Outline1.SelectedItem].Index));
end;

end.

 

Re:OnDrawItem


You can use the inherited-procedure to let the node be draw at first, and
after that draw some pieces of that node again.

Timo

howlerrr <howle...@bellatlantic.net> schreef in artikel
<01bc24bd$aa005a60$416df5cc@howlerrr>...

Quote
> I need to code the OnDrawItem of a TOutline.  I need to do this so that
> can draw on the canvas to allow me to change the canvas.font color of
> particular TOutlineNodes.  I am successfull if I only have 1 level to the
> outline.  If I addchild, it does not appear to draw like an outline
> normally does.  Do I have to do all the code to draw the outline levels
> with the proper parent?

Other Threads