Cita:
Empezado por Neftali
Creo que eso es orientación vertical, no centrado vertical (que es lo que pide mcsebas).
De todas formas es interesante el código.
Guardado.
|
Sabes que creo que tenes razón...
mcsebas, la función Api
DrawText hace muy simple centrar texto de forma vertical u horizontal.
Código Delphi
[-]
procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
var
R: TRect;
Grid: TDBGrid;
begin
R:= Rect;
Grid:= TDBGrid(Sender);
FillRect(Grid.Canvas.Handle, R, HBRUSH(Grid.Color));
DrawText(Grid.Canvas.Handle, PChar(Column.Field.AsString),-1, R, DT_SINGLELINE or
DT_VCENTER or DT_CENTER); end;
Y tampoco es complicado usando los métodos de
TCanvas:
Código Delphi
[-]
procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
var
Grd: TDBGrid;
Str: string;
begin
Grd:= TDBGrid(Sender);
Str:= Column.Field.AsString;
Grd.Canvas.FillRect(Rect);
Grd.Canvas.TextRect(Rect,
(Rect.Right + Rect.Left-Grd.Canvas.TextWidth(Str)) shr 1, (Rect.Top + Rect.Bottom-Grd.Canvas.TextHeight(Str))shr 1, Str);
end;
Cualquiera de los dos hace bién la taréa, elegí el de tu gusto. Evité el uso de
with para que el código resulte mas claro.
Saludos