Fórum Como colocar um texto e um bmp em uma célula no Drawgrid ? #369587
03/04/2009
0
Estou com um problemão. Tenho que colocar um texto (máximo de 8 caracteres) e uma figura BMP em uma mesma célula na Drawgrid ou Stringgrid. Isso pode ser feito? Ou existe algum componente que me permite fazer isso?
Obrigado.
Flaviodfp
Curtir tópico
+ 1Posts
03/04/2009
Lehapan
dá uma olhada no código abaixo e veja se te ajuda.
procedure TfrmAtualizacao.stgrTesteDrawCell(Sender: TObject; ACol,
ARow: Integer; Rect: TRect; State: TGridDrawState);
var
Texto: string;
begin
{ Indice_da_Coluna -> índice da coluna que deve ser colocada a imagem com o texto }
if ACol = Indice_da_Coluna then
begin
{ Coloca a imagem na célula }
stgrTeste.Canvas.FillRect( Rect );
stgrTeste.Canvas.StretchDraw( Rect, ImgTeste.Picture.Graphic );
{ Para copiar somente os 8 primeiros caracteres }
Texto := Copy( stgrProcesso.Cells[ACol, ARow], 1, 8 );
{ Escreve o texto na célula }
stgrTeste.Canvas.Brush.Style := bsClear;
stgrTeste.Canvas.TextOut( Rect.Left + 2, Rect.Top + 2, Texto );
end
;
end;
espero ter ajudado
Gostei + 0
03/04/2009
Lehapan
Componentes utilizados:
stgrTeste: TStringGrid;
ImgTeste: TImage; { Componente já com a sua imagem carregada }
Gostei + 0
03/04/2009
Flaviodfp
O texto tá aparecendo em todas as células.
Na minha query: dependendo do status do apartamento, por exemplo: apto 101, status 1 = Ocupado (coloco a figura de Ocupado + ´Apto ´101´, apto 103, status 2 = Manutenção (coloco a figura de Manutenção + ´Apto ´103´, etc.
Me desculpe, eu deveria ter colocado este texto na minha dúvida.
Gostei + 0
03/04/2009
Lehapan
procedure TForm.stgrTesteDrawCell(Sender: TObject; ACol,
ARow: Integer; Rect: TRect; State: TGridDrawState);
var
Texto: string;
[b]gfcStatus: TGraphic;[/b]
begin
{ Indice_da_Coluna -> índice da coluna que deve ser colocada a imagem com o texto }
if ACol = Indice_da_Coluna then
begin
[b]gfcStatus := RetornaImagemStatus( stgrTeste.Cells[Indice_da_Coluna_Status, ARow] );[/b]
{ Coloca a imagem na célula }
stgrTeste.Canvas.FillRect( Rect );
[b]if gfcStatus <> nil then
stgrTeste.Canvas.StretchDraw( Rect, gfcStatus )
;[/b]
{ Para copiar somente os 8 primeiros caracteres }
Texto := Copy( stgrTeste.Cells[ACol, ARow], 1, 8 );
{ Escreve o texto na célula }
stgrTeste.Canvas.Brush.Style := bsClear;
stgrTeste.Canvas.TextOut( Rect.Left + 2, Rect.Top + 2, Texto );
end
;
end;
[b]
function TForm.RetornaGraphicStatus(Status: string): TGraphic;
begin
Result := nil;
if Status = ´1´ then
Result := imgOcupado.Picture.Graphic
else
if Status = ´2´ then
Result := imgManutencao.Picture.Graphic
;
;
end;[/b]Gostei + 0
07/04/2009
Flaviodfp
ats,
flaviodfp.
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)