DrawGrid

Delphi

07/03/2006

Ola Pessoal,

Gostaria de saber como carregar uma imagem em uma celula especifica do componente [b:3350a0e6e0]DrawGrid[/b:3350a0e6e0]???

Posso carregar tb imagens em um [b:3350a0e6e0]StringGrid[/b:3350a0e6e0]??

Qual desses devo utilizar???

O que estou tentando fazer é abrir um (stringGrid ou drawGrid) com 4 imagens, ou seja, uma imagem em cada célula. Como posso fazer isso?

Gostaria q de uma ajuda

vlw :lol:


Fernando Piccini

Fernando Piccini

Curtidas 0

Respostas

Bon Jovi

Bon Jovi

07/03/2006

Coloca dois bmps (teste1.bmp e teste2.bmp) na raiz do C e rode esse exemplo:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Grids, StdCtrls;

type
  TImagem = class(TObject)
    Picture: TPicture;
    public
      constructor Create;
      destructor Destroy; override;
  end;

  TForm1 = class(TForm)
    StringGrid1: TStringGrid;
    Button1: TButton;
    procedure StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
      Rect: TRect; State: TGridDrawState);
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    { Private declarations }
    Imagem: TImagem;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

constructor TImagem.Create;
begin
  Picture := TPicture.Create;
end;

destructor TImagem.Destroy;
begin
  Picture.Free;  
  inherited;  
end;

procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);
var
  Objeto: TObject;
begin
  Objeto := StringGrid1.Objects[ACol, ARow];

  if Assigned(Objeto) and (Objeto is TImagem) then
    StringGrid1.Canvas.StretchDraw(Rect, TImagem(Objeto).Picture.Graphic);
end;

procedure TForm1.FormCreate(Sender: TObject);
var
  i: integer;
begin
  for i := 1 to 2 do
  begin
    Imagem := TImagem.Create;
    Imagem.Picture.LoadFromFile(´c:\teste´ + IntToStr(i) + ´.bmp´);
    StringGrid1.Objects[1, i] := Imagem;    
  end;
end;

procedure TForm1.FormDestroy(Sender: TObject);
var
  i: integer;
  Objeto: TObject;
begin
  for i := 0 to StringGrid1.RowCount - 1 do
  begin
    Objeto := StringGrid1.Objects[1, i];
    if Assigned(Objeto) and (Objeto is TImagem) then
      FreeAndNil(Objeto);
  end;
end;

end.


object Form1: TForm1
  Left = 192
  Top = 107
  Width = 696
  Height = 480
  Caption = ´Form1´
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = ´MS Sans Serif´
  Font.Style = []
  OldCreateOrder = False
  OnCreate = FormCreate
  OnDestroy = FormDestroy
  PixelsPerInch = 96
  TextHeight = 13
  object StringGrid1: TStringGrid
    Left = 4
    Top = 4
    Width = 320
    Height = 120
    TabOrder = 0
    OnDrawCell = StringGrid1DrawCell
  end
  object Button1: TButton
    Left = 4
    Top = 132
    Width = 75
    Height = 25
    Caption = ´Button1´
    TabOrder = 1
  end
end



GOSTEI 0
Fernando Piccini

Fernando Piccini

07/03/2006

Bon Jovi

Valeu pela ajuda

fico muito grato

flw :D


GOSTEI 0
POSTAR