### Bookstore

 Computer Math and Games in Pascal (preview) Lazarus Handbook

### Author Topic: OnDrawColumnTitle, how does it works?  (Read 2103 times)

#### hamacker

• New Member
• Posts: 18
##### OnDrawColumnTitle, how does it works?
« on: November 09, 2021, 12:47:28 am »
OnDrawColumnTitle, how does it works?
I try code bellow like OnDrawColumnCell, but it does not work - empty title cell.

const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
if DataCol=0 then
begin
Canvas.FillRect(Rect); // limpando a celula com rect vazio
imagelist_colGrids.Draw(Canvas,
Rect.CenterPoint.x-(imagelist_colGrids.Width div 2),
Rect.CenterPoint.y-(imagelist_colGrids.Height div 2),
4); // imageindex
end;

• Hero Member
• Posts: 568
##### Re: OnDrawColumnTitle, how does it works?
« Reply #1 on: November 10, 2021, 10:16:46 am »
Hi,
Code: Pascal  [Select][+][-]
1. procedure TForm1.DBGrid1DrawColumnTitle(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState);
2. begin
3.      with (Sender as TDBGrid) do
4.      begin
5.        if DataCol mod 2=0 then
6.        begin
7.        Canvas.Brush.Color:=clYellow;
8.        Canvas.FillRect(Rect);
9.        Canvas.TextOut(Rect.Left,Rect.Top,Datasource.DataSet.Fields[DataCol].FieldName);
10.        end;
11.      end;
12. end;
If Ide=Lazarus 2.0.10 32 Bit and Os=Win 10 Home 64 Bit then Get up and do something useful! Because God is the helper of those who start again;

#### hamacker

• New Member
• Posts: 18
##### Re: OnDrawColumnTitle, how does it works?
« Reply #2 on: November 11, 2021, 03:54:14 am »
Can not draw a picture instead Text?

• Hero Member
• Posts: 568
##### Re: OnDrawColumnTitle, how does it works?
« Reply #3 on: November 11, 2021, 06:23:39 am »
Certainly ;
Code: Pascal  [Select][+][-]
1. procedure TForm1.DBGrid1DrawColumnTitle(Sender: TObject; const Rect: TRect;DataCol: Integer; Column: TColumn; State: TGridDrawState);
2.   var
3.     buf:Tbitmap;
4. begin
5.      with (Sender as TDBGrid) do
6.      begin
7.        if DataCol mod 2=0 then
8.        begin
9.        buf:=Tbitmap.Create;
10.        ImageList1.GetBitmap(0, buf);
11.        canvas.Draw(Rect.Left,Rect.Top,buf);
12.        Canvas.TextOut(buf.Width+ Rect.Left,Rect.Top,Datasource.DataSet.Fields[DataCol].FieldName);
13.        buf.Free;
14.        end;
15.      end;
16. end;
If Ide=Lazarus 2.0.10 32 Bit and Os=Win 10 Home 64 Bit then Get up and do something useful! Because God is the helper of those who start again;