Ver Mensaje Individual
  #4  
Antiguo 27-11-2007
Avatar de Lepe
[Lepe] Lepe is offline
Miembro Premium
 
Registrado: may 2003
Posts: 7.424
Reputación: 29
Lepe Va por buen camino
Esa imagen que pones tiene toda la pinta de ser un JFControls, un grid muy tuneable. Son componentes de pago.

Buscando por mis bibliotecas he encontrado una forma "fácil" de usar el método de fjcg02. Copia todo en una nueva unidad y ponle el nombre lpCanvas.pas:
Código Delphi [-]
unit lpCanvas;

interface
  uses Graphics,windows;

type TAlignText = (atTopLeft=0, atTopCenter, atTopRight,
                   atCenterLeft, atCenter, atCenterRight,
                   atBottomLeft, atBottomCenter, atBottomRight);

procedure PaintText(ACanvas: TCanvas; const ARect: TRect;
                       const Line:string; Align:TAlignText;
                       const FillBackground:Boolean = false);

implementation

uses sysutils;

const
 Offset = 2;

procedure PaintText(ACanvas: TCanvas; const ARect: TRect;
                       const Line:string; Align:TAlignText;
                       const FillBackground:Boolean = false);
var x,y,CenterX, CenterY:integer;
   Options :integer;
   S: array[0..255] of Char;
begin
  Options := ETO_CLIPPED;

  if FillBackground  then
    Options := options or ETO_OPAQUE;

  with ARect, Acanvas do
  begin
    CenterY := (Bottom - Top - TextHeight(Line)) div 2;
    CenterX := (Right - Left - TextWidth(line)) div 2;
    x:= Offset;
    y:= Offset;
    case Align of
     atTopLeft      :begin
                      x := left + Offset ;
                     end;
     atTopCenter    :begin
                      x := left + CenterX;
                     end;
     atTopRight     :begin
                      x := Right - Offset - TextWidth(Line);
                     end;
     atCenterLeft   :begin
                      x:= Left+ Offset;
                      y:= CenterY;
                     end;
     atCenter       :begin
                      x:= CenterX;
                      y:= CenterY;
                     end;
     atCenterRight  :begin
                      x:= Right - Textwidth(line) - Offset;
                      y:=  CenterY;
                     end;
     atBottomleft   :begin
                      y:=  Bottom - Textheight(Line) - Offset;
                     end;
     atBottomCenter :begin
                      x:= CenterX;
                      y:= Bottom - Offset - Textheight(Line);
                     end;
     atBottomRight  :begin
                      x:= Right - TextWidth(line) - Offset;
                      y:= Bottom - Textheight(Line)-Offset;
                     end;
    end;
    ExtTextOut(Handle, x, y, options,@ARect,  StrPCopy(S,Line),length(line),nil);
  end;
end;


end.

Forma de uso:
Código Delphi [-]
uses lpCanvas;

// Al dbGrid, le pones a false la propiedad DefaultDrawing
//En el evento OnDrawColumnCell del grid, escribes:
PaintText(Canvas, Rect,                      //parámetros del propio evento OnDrawColumnCell
             'Mi texto Linea1', atTopLeft,
             true); // aqui decimos que pinte el fondo

PaintText(Canvas, Rect,                      //parámetros del propio evento OnDrawColumnCell
             'Mi texto Linea 2', atBottomRight,  //segunda línea alineada a la derecha
             False); // Ahora no pintamos el fondo, porque se borraría la primera línea.

Como ves tienes 9 formas de alinear texto dentro de la celda, más que suficiente .

Saludos
__________________
Si usted entendió mi comentario, contácteme y gustosamente,
se lo volveré a explicar hasta que no lo entienda, Gracias.

Última edición por Lepe fecha: 27-11-2007 a las 20:06:15.
Responder Con Cita