Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > Varios
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

Grupo de Teaming del ClubDelphi

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 21-09-2004
ctronx ctronx is offline
Miembro
 
Registrado: jun 2004
Posts: 214
Poder: 20
ctronx Va por buen camino
Unhappy alinear a la derecha texto de un stringgrid

Saludos, como podria alinear a la derecha el contenido de una columna de un stringgrid, tomando en cuenta que mi aplicacion es CLX.

Gracias por la ayuda que puedan darme.
Responder Con Cita
  #2  
Antiguo 22-09-2004
Avatar de yusnerqui
yusnerqui yusnerqui is offline
Miembro
 
Registrado: mar 2004
Ubicación: Cuba
Posts: 679
Poder: 21
yusnerqui Va por buen camino
Primero que nada quiero pedirte disculpa por mi falta de conocimiento (No se que es una aplicación CLX ), pero quizás el truco 234 de Trucomanía te pueda ayudar, a continuación te lo cito.

Cita:
Empezado por Trucomanía
Pon este código en el evento OnDrawCell de tu StringGrid:

Código Delphi [-]
procedure TForm1.StringGrid1DrawCell(Sender: TObject; Col, Row: Integer;
  Rect: TRect; State: TGridDrawState);
var sCad:String;
    i:integer;
    bEsNum:Bool;
begin 
  if StringGrid1.Cells[Col,Row] <> '' then 
  begin 
     bEsNum := True;
     sCad := StringGrid1.Cells[Col,Row];
     for i:=1 to length(sCad) do 
         if not (sCad[i] in ['0'..'9','-']) then bEsNum := False;
     if bEsNum then 
     begin 
        {'%15 para una longitud maxima de 15 caracteres}
        {'%15 for a Max Length of 15 characteres}
        sCad := Format('%15.0n',[StrToFloat(StringGrid1.Cells[Col,Row])]);
        with StringGrid1 do 
          with Canvas,Rect do 
          begin 
             i:=Right-TextWidth(sCad+' ');
             Canvas.FillRect(Rect);
             Canvas.TextOut(i,Top+2,sCad);
          end; 
     end; 
  end; 
end;
Espero que eso te pueda ayudar.

Un saludo

__________________
Lo importante no es llegar primero, sino saber llegar.

Para que puedas llegar mejor lee la Guia de Estilo

Responder Con Cita
  #3  
Antiguo 22-09-2004
ctronx ctronx is offline
Miembro
 
Registrado: jun 2004
Posts: 214
Poder: 20
ctronx Va por buen camino
Unhappy

Saludos, gracias por tu ayuda pero tu ejemplo no me permite especificar una determinada columna para alinear a la derecha.

este ejemplo si me pide la columna que quiero alinear pero me marca que no esta declarada ó definida DrawText, a de faltar una Unit ó algo asi, espero me puedan ayudar.

Código Delphi [-]

procedure Tfrmventas.StringGrid1DrawCell(Sender: TObject; ACol,
  ARow: Integer; Rect: TRect; State: TGridDrawState);
  begin
if ACol=2 then // voy a alinear a la derecha la 3ª columna
if ARow>0 then //No quiero alinear la línea de títulos
with StringGrid1 do
     begin
     Canvas.FillRect(Rect);
     DrawText(Canvas.Handle,PChar(Cells[Acol,ARow]),-1,Rect,
          DT_CENTER or DT_RIGHT or DT_SINGLELINE);
     end;

end;
Responder Con Cita
  #4  
Antiguo 22-09-2004
Avatar de roman
roman roman is offline
Moderador
 
Registrado: may 2003
Ubicación: Ciudad de México
Posts: 20.269
Poder: 10
roman Es un diamante en brutoroman Es un diamante en brutoroman Es un diamante en bruto
Cita:
Empezado por ctronx
pero tu ejemplo no me permite especificar una determinada columna para alinear a la derecha.
¿Cómo está eso de que no te permite elegir la columna? ¡Se trata del mismo evento! Así que en ambos casos puedes usar condicionales para ACol y ARow.

// Saludos
Responder Con Cita
  #5  
Antiguo 22-09-2004
Avatar de yusnerqui
yusnerqui yusnerqui is offline
Miembro
 
Registrado: mar 2004
Ubicación: Cuba
Posts: 679
Poder: 21
yusnerqui Va por buen camino
Esto Funciona

Como bien dice el amigo roman, se trata del mismo evento así que con solo unas pequeñas modificaciones lo podrás adaptar a lo que quieres.
Código Delphi [-]
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);
var sCad:String;
    i: integer;
begin 
  if ACol=2 then // voy a alinear a la derecha la 3ª columna
  if ARow>0 then //No quiero alinear la línea de títulos
    if StringGrid1.Cells[ACol,ARow] <> '' then 
    begin 
       sCad := StringGrid1.Cells[ACol,ARow];
         with StringGrid1 do 
            with Canvas,Rect do 
            begin 
               i:=Right-TextWidth(sCad+' ');
               Canvas.FillRect(Rect);
               Canvas.TextOut(i,Top+2,sCad);
            end;      
    end; 
end;


Esto lo probé y me funciona.

Espero te Ayude.

Un saludo
__________________
Lo importante no es llegar primero, sino saber llegar.

Para que puedas llegar mejor lee la Guia de Estilo

Responder Con Cita
  #6  
Antiguo 23-09-2004
ctronx ctronx is offline
Miembro
 
Registrado: jun 2004
Posts: 214
Poder: 20
ctronx Va por buen camino
Thumbs up

Ok, muchas gracias a ambos.
Responder Con Cita
  #7  
Antiguo 06-06-2006
Avatar de BlueSteel
[BlueSteel] BlueSteel is offline
Miembro Premium
 
Registrado: may 2003
Ubicación: Concepción - Chile
Posts: 2.310
Poder: 23
BlueSteel Va por buen camino
problema al alinear

Hola amigos...

tengo un pequeñisimo problema... quise ejecutar esta sentencia.. pero me da el siguente error

[Error] Unit5.pas(399): Undeclared identifier: 'Right'

he tratado de solucionarlo.,... pero no se como.. el codigo es tengo es el sgte:

Código Delphi [-]
procedure TOrden.Items_PasoDrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);
var  sCad : String;
    i : Integer;
begin
     If (ACol=2) Or (ACol=3) Then
        If Items_Paso.Cells[ACol,ARow] <> '' Then
           Begin
                sCad := Items_Paso.Cells[ACol,ARow];
                With Items_Paso Do
                Begin
                    i:=Right-TextWidth(sCad+' ');
                     Canvas.FillRect(Rect);
                     Canvas.TextOut(i,Top+2,sCad);
                End;
           End;
end;

espero me puedan ayudar..
__________________
BlueSteel
Responder Con Cita
  #8  
Antiguo 06-06-2006
Avatar de BlueSteel
[BlueSteel] BlueSteel is offline
Miembro Premium
 
Registrado: may 2003
Ubicación: Concepción - Chile
Posts: 2.310
Poder: 23
BlueSteel Va por buen camino
ya lo arregle.. me habia comido una linea.. sorry..y gracias
__________________
BlueSteel
Responder Con Cita
  #9  
Antiguo 07-09-2007
[FGarcia] FGarcia is offline
Miembro Premium
 
Registrado: sep 2005
Ubicación: Cordoba, Veracruz, México
Posts: 1.123
Poder: 20
FGarcia Va por buen camino
Hola!

Resucitando este hilo ya que necesito hacer algo similar ¿cual fue la linea que te comiste Blue Steel?
Responder Con Cita
  #10  
Antiguo 07-09-2007
Avatar de BlueSteel
[BlueSteel] BlueSteel is offline
Miembro Premium
 
Registrado: may 2003
Ubicación: Concepción - Chile
Posts: 2.310
Poder: 23
BlueSteel Va por buen camino
Cita:
Empezado por FGarcia Ver Mensaje
Hola!

Resucitando este hilo ya que necesito hacer algo similar ¿cual fue la linea que te comiste Blue Steel?

Hola.. en realidad ya ni me acuerdo.. por que fue hace mas de 1 año... pero si te sale error.. por que mejor no pones tu codigo...
__________________
BlueSteel
Responder Con Cita
  #11  
Antiguo 07-09-2007
[FGarcia] FGarcia is offline
Miembro Premium
 
Registrado: sep 2005
Ubicación: Cordoba, Veracruz, México
Posts: 1.123
Poder: 20
FGarcia Va por buen camino
JEJE!

Como me fui a comer no habia probado nada del codigo pero copy & paste el tuyo, le cambie el nombre del stringgrid y me aparece el mismo error que mencionas

edito: OK Corregido

Código Delphi [-]
procedure TfrmMain.StringGrid1DrawCell(Sender: TObject; ACol,
  ARow: Integer; Rect: TRect; State: TGridDrawState);
var sCad: String;
    i: Integer;
begin
  If (ACol=1) Or (ACol=2) Then
    If StringGrid1.Cells[ACol,ARow] <> '' Then
      Begin
        sCad := StringGrid1.Cells[ACol,ARow];
        With StringGrid1 Do
          with Canvas,Rect do   //ESTA es la linea que faltaba
          Begin
            i:=Right-TextWidth(sCad+' ');
            Canvas.FillRect(Rect);
            Canvas.TextOut(i,Top+2,sCad);
          End;
      End;

end;

Última edición por FGarcia fecha: 07-09-2007 a las 22:02:58.
Responder Con Cita
Respuesta



Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro


La franja horaria es GMT +2. Ahora son las 10:11:55.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi