[delphi-br] Re: Re: StringGrid - como alinhar valores?

2005-06-07 Por tôpico Shally
Muito grata pela ajuda mas não consegui obter o resultado que era 
centralizar os valores. Simplesmente isto fez com que eles sumissem 
da grid. :(

Não há uma maneira mais fácil



--- Em delphi-br@yahoogrupos.com.br, Romario (Listas) 
[EMAIL PROTECTED] escreveu
 Se você estiver utilizando os componentes VCL:
 
 {  }
 
 Procedure WriteText(ACanvas: TCanvas; Const ARect: TRect; ACol, 
ARow:
 Integer; Const Text: String; Format: Word);
 var
S: Array[0..255] of Char;
B, R: TRect;
 Begin
 
With ACanvas, ARect do
Begin
 
 Case Format of
 
  DT_LEFT: ExtTextOut(Handle, Left + ACol, Top + ARow, 
ETO_OPAQUE or
   ETO_CLIPPED, @ARect, StrPCopy(S, Text), Length(Text), 
Nil);
 
  DT_RIGHT: ExtTextOut(Handle, Right - TextWidth(Text) - 3, Top +
ARow, ETO_OPAQUE or ETO_CLIPPED, @ARect, StrPCopy(S, 
Text),
Length(Text), nil);
 
  DT_CENTER: ExtTextOut(Handle, Left + (Right - Left - TextWidth
(Text))
 div 2, Top + DY, ETO_OPAQUE or ETO_CLIPPED, @ARect,
 StrPCopy(S, Text), Length(Text), Nil);
 
 End;
 
End;
 
 End;
 
 {  }
 
 Procedure TStringGrid1.DrawCell(ACol, ARow: Longint; Rect: TRect; 
State:
 TGridDrawState);
 Var
 
Procedure Display(Const S: String; Alignment: TAlignment);
Const
 Formats: Array[TAlignment] of Word = (DT_LEFT, DT_RIGHT, 
DT_CENTER);
 Begin
 
  WriteText(Canvas, Rect, 2, 2, S, Formats[Alignment]);
 
 End;
 
 Begin
 
Case Row of
 
 0 : { Center column headings }
 
  If (Col  ColCount) then
 
   Display(Cells[ACol, ARow], taCenter)
 
  Else
 
   Display(Cells[ACol, ARow], taRight);
 
End;
 
 End;
 
 {  }
 
 Senão, se estiver utilizando os componentes CLX:
 
 ++--+---
---+
 |Flag|   Type   |   
Meaning|
 ++--+---
---+
 |AlignLeft   |Horizontal|Align text to the left edge of the 
rectangle. |
 ++--+---
---+
 |AlignRight  |Horizontal|Align text to the right edge of the 
rectangle.|
 ++--+---
---+
 |AlignHCenter|Horizontal|Center text horizontally in the 
rectangle.|
 ++--+---
---+
 |AlignTop|Vertical  |Align text to the top edge of the 
rectangle.  |
 ++--+---
---+
 |AlignBottom |Vertical  |Align text to the bottom edge of the 
ectangle.|
 ++--+---
---+
 |AlignVCenter|Vertical  |Center text vertically in the 
rectangle.  |
 ++--+---
---+
 | You can also use the AlignCenter flag to indicate AlignHCenter 
+ |
 | 
AlignVCenter.|
 +---
---+
 
 
 Veja um exemplo (CLX) em que adicionei alguns comentários para um 
melhor
 entendimento:
 
 {  }
 
 Procedure Tfrm_anamne.grd_atvfisDrawCell(Sender: TObject; ACol, 
ARow:
 Integer;
  Rect: TRect; State:
 TGridDrawState);
 Begin
 
 // Se forem colunas da linha zero ou linhas da coluna zero e 
dois...
 If ( ARow = 0 ) or ( ACol in [0, 2] ) then
 Begin
 
   // Se forem colunas da linha zero...
   If ( ARow = 0 ) then
 
 // Altera a cor do texto para preto.
 grd_atvfis.Canvas.Font.Color := clBlack;
 
   // Limpa as células.
   grd_atvfis.Canvas.FillRect( Rect );
 
   // Redesenha e centraliza o texto nas células (note o nº 4 ao 
final).
   grd_atvfis.Canvas.TextRect( Rect, Rect.Left + 2, Rect.Top + 2,
   grd_atvfis.Cells[ACol, ARow], 4 );
 
 End
 
 // Senão... (o texto continuará em Azul)
 Else
 Begin
 
   // Limpa as células.
   grd_atvfis.Canvas.FillRect( Rect );
 
   // Exibe e alinha à esquerda o texto das células (o nº ao 
final é
 omitido).
   grd_atvfis.Canvas.TextRect( Rect, Rect.Left + 2, Rect.Top + 2,
 grd_atvfis.Cells[ACol, 
ARow] );
 
 End;
 
 End;
 
 {  }
 
 Espero que isso ajude!
 
 Sds,
 
 Romario
 
 
 
 Shally escreveu:
  Sim, preciso da String Grid pois trabalho com dados que vem de um 
BD, 
  cálculos são realizados, etc e tal para depois os dados serem 
  mostrados nesta Grid. 
  Sabe como posso centralizar esses valores?
 
   
   
   
 
 Yahoo! Mail, cada vez melhor: agora com 1GB de espaço grátis! 
http://mail.yahoo.com.br





-- 
 FAVOR REMOVER ESTA PARTE AO RESPONDER ESTA MENSAGEM 

Para ver as mensagens antigas, acesse:
 

[delphi-br] Re: Re: StringGrid - como alinhar valores?

2005-06-07 Por tôpico Shally
Assim...
Tenho aqui a seguinte linha de comando:


  StringGridDetalhe.Cells[Col,Lin] := FormatFloat
('#,##0.00%',vTaxa);   
  StringGridDetalhe.Cells[Col+1,Lin] := FormatFloat('#,##0.00',
(Valor/100));


Como faço para alinhar o texto que aparecerá na grid quando executar 
o programa?
Há algo do tipo:
   StringGridDetalhe.Cells[Col,Lin].alignment := alCenter;  

Testei mas não existe.

O que faço??






--- Em delphi-br@yahoogrupos.com.br, Romario (Listas) 
[EMAIL PROTECTED] escreveu
 Se você estiver utilizando os componentes VCL:
 
 {  }
 
 
 
 
 Shally escreveu:
  Sim, preciso da String Grid pois trabalho com dados que vem de um 
BD, 
  cálculos são realizados, etc e tal para depois os dados serem 
  mostrados nesta Grid. 
  Sabe como posso centralizar esses valores?
 
   





-- 
 FAVOR REMOVER ESTA PARTE AO RESPONDER ESTA MENSAGEM 

Para ver as mensagens antigas, acesse:
 http://br.groups.yahoo.com/group/delphi-br/messages

Para falar com o moderador, envie um e-mail para:
 [EMAIL PROTECTED] ou [EMAIL PROTECTED]
 
Links do Yahoo! Grupos

* Para visitar o site do seu grupo na web, acesse:
http://br.groups.yahoo.com/group/delphi-br/

* Para sair deste grupo, envie um e-mail para:
[EMAIL PROTECTED]

* O uso que você faz do Yahoo! Grupos está sujeito aos:
http://br.yahoo.com/info/utos.html