2005. március 31., csütörtök

Change fonts between columns in a TStringGrid


Problem/Question/Abstract:

How to change fonts between columns in a TStringGrid

Answer:

You must write the text to the canvas after setting the font. Use Canvas.TextRect for this:

procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);
begin
  with Sender as TStringGrid do
  begin
    case aCol of
      0: canvas.font.name := 'Courier New';
      1..5: canvas.font.name := 'Arial';
    end;
    Canvas.TextRect(Rect, Rect.Left + 2, Rect.Top + 2, Cells[ACol, ARow]);
  end;
end;

Nincsenek megjegyzések:

Megjegyzés küldése