Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Varios (https://www.clubdelphi.com/foros/forumdisplay.php?f=11)
-   -   Como agregar una imagen de una ImageList en un Stringgrid (https://www.clubdelphi.com/foros/showthread.php?t=97010)

compuin 12-11-2024 18:54:59

Como agregar una imagen de una ImageList en un Stringgrid
 
Hola amigos,

Tengo este codigo pero no tengo idea de como agregar las imagenes que tengo almacenadas en un Imagelist. Si alguien me puede orientar estare agradecido

Código:

procedure TFormMain.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);
var
  Alin: integer;
begin
  with Sender as TStringGrid do
  begin
    if ARow = 0 then
      Alin:= DT_CENTER
    else
      Alin:= DT_RIGHT;

    if ACol = 0 then
      Alin:= DT_LEFT;

    if ARow = 0 then
      Alin:= DT_CENTER;

    // Dibujar texto centrado horizontal y verticalmente o a la derecha
    InflateRect(Rect, -1, -1);
    Canvas.FillRect(Rect);
    InflateRect(Rect, -3, -3);
    DrawText(Canvas.Handle, PAnsiChar(Cells[ACol, ARow]), Length(Cells[ACol, ARow]), Rect,
        Alin or DT_VCENTER or DT_SINGLELINE);
  end;
end;


newtron 12-11-2024 19:02:45

Este es un código que tengo sobre un componente nuestro que deriva del StringGrid así que podrás interpretarlo fácilmente


Código Delphi [-]
procedure TFormManejaVerifactu.NTStringGrid3DrawCell(Sender: TObject; ACol,
  ARow: Integer; Rect: TRect; State: TGridDrawState);
var
  SelectedPicture: TBitmap;
begin
  // Resultados del envío: 0=Enviado 1=No enviado(errores) 2=Enviado con errores
  if NtStringGrid3.RowCount <2 then
    exit;
  with Sender as TStringGrid do begin

    if NtStringGrid3.ValorCeldaPorCampoYFila('RESULTADO',ARow)<>'' then begin
      if (ACol=0) then begin
        if NtStringGrid3.Cells[0,ARow]<>'' then begin
          SelectedPicture:=TBitmap.Create;
          If NtStringGrid3.Cells[0,ARow]='0' then begin
            ImageList.GetBitmap(0, SelectedPicture);
          end else if NtStringGrid3.Cells[0,ARow]='1' then begin
            ImageList.GetBitmap(1, SelectedPicture);
          end else if NtStringGrid3.Cells[0,ARow]='2' then begin
            ImageList.GetBitmap(2, SelectedPicture);
          end;
          NtStringGrid3.Canvas.Draw(Rect.Left-2, Rect.Top, SelectedPicture);
          SelectedPicture.Free;
        end;
      end;
    end;

  end;

end;


Saludos.

Neftali [Germán.Estévez] 12-11-2024 19:46:12

Un par de ejemplos que puedes encontrar en el FTP del club, aunque seguro que si buscas hay más...

https://terawiki.clubdelphi.com/Delp...n_imagenes.zip
https://terawiki.clubdelphi.com/Delp..._imagenes2.zip
https://terawiki.clubdelphi.com/Delp...n_imagenes.zip

compuin 15-11-2024 14:05:41

Muchas gracias a todos


La franja horaria es GMT +2. Ahora son las 18:25:40.

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