Ver Mensaje Individual
  #4  
Antiguo 29-08-2013
Avatar de ecfisa
ecfisa ecfisa is offline
Moderador
 
Registrado: dic 2005
Ubicación: Tres Arroyos, Argentina
Posts: 10.508
Reputación: 36
ecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to behold
Hola giocatore.
Cita:
Empezado por giocatore Ver Mensaje
hay alguna manera de hacerlo con dbgrid o sin usar un componente externo???
Si claro que la hay.

Por ejemplo:
Código Delphi [-]
...
type
  TDBGrid = class(DBGrids.TDBGrid)
  private
  protected
    procedure DrawCell(ACol, ARow: Integer; ARect: TRect; State: TGridDrawState); override;
  public
  end;

  TForm1 = class(TForm)
    Table1: TTable;
    DataSource1: TDataSource;
    DBGrid1: TDBGrid;
    procedure FormCreate(Sender: TObject);
  private
  public
  end;

var
  Form1: TForm1;

implementation 

procedure TDBGrid.DrawCell(ACol, ARow: Integer; ARect: TRect; State: TGridDrawState);
const
  ALGN : array[0..2] of Integer = (DT_LEFT, DT_RIGHT, DT_CENTER);
var
  CurrTit : string;
  CurrCol : TColumn;
  uFormat : Integer;
begin
  TDBGrid(Self).RowHeights[0] := 2 * TDBGrid(Self).DefaultRowHeight;
  if (ARow = 0) and (ACol > 0) and (ColCount > 0) then
  begin
    CurrCol := Columns[ACol - Integer(dgIndicator in Options)];
    CurrTit := CurrCol.Title.Caption;
    Canvas.Font := CurrCol.Font;
    Canvas.FillRect(ARect);
    uFormat := ALGN[Integer(CurrCol.Title.Alignment)] + DT_WORDBREAK;
    DrawText(Canvas.Handle, PChar(CurrTit), -1, ARect, uFormat);
  end
  else
    Inherited;
end;

// Ejemplo: Un titulo y su alineación
procedure TForm1.FormCreate(Sender: TObject);
begin
  DBGrid1.Columns[0].Title.Caption :=
    'Titulo muy largo para que pueda verse' + #10 +
    'con mayor clariodad en dos renglones';
  DBGrid1.Columns[0].Title.Alignment := taCenter;
end;
...
Pero coincido con ElDioni, con que es mas simple y reusable utilizar un componente de tercero, o bién crearte uno incorporándole este código u otro similar.

Saludos
__________________
Daniel Didriksen

Guía de estilo - Uso de las etiquetas - La otra guía de estilo ....
Responder Con Cita