Fórum Exibindo imagens de um ImageList #330133
27/09/2006
0
Alguem sabe se tem a possibilidade de exibir todas as imagens contidas em um TImageList em algum outro componente?
ex: tenho um campo de uma determinada tabela chamada ´CODIGO_IMAGEM - INTEGER´. quero exibir (visualmente e em runtime) todas as imagens que tenho no meu ImageList em algum lugar para poder pegar o codigo Index dessa imagem do ImageList e salva-lo no referido campo da tabela...
abraços!!!
Mahdak
Curtir tópico
+ 0Posts
27/09/2006
Siam
Gostei + 0
27/09/2006
Aloizio Castro
function GetIndexFromImageList(ImgLst : TImageList; nCol, nRow: Word): Integer; var Frm : TForm; SpdBtn : TBitBtn; nL, nC : Word; nIdx : Word; begin Frm := TForm.Create(Nil); with Frm do begin Width := ImgLst.Width * nCol + 04; Height := ImgLst.Height * nRow + 04; BorderStyle := bsNone; Left := Mouse.CursorPos.X; Top := Mouse.CursorPos.Y; AutoSize := True; end; nIdx := 0; for nL := 1 to nRow do begin for nC := 1 to nCol do begin SpdBtn := TBitBtn.Create(Frm); with SpdBtn do begin Parent := Frm; Kind := bkClose; Glyph := nil; Caption := ´´; NumGlyphs := 1; SetBounds(nC * (ImgLst.Width +6) - (ImgLst.Width +6) + 1, nL * (ImgLst.Height+6) - (ImgLst.Height+6) + 1, ImgLst.Width + 6, ImgLst.Height + 6); ImgLst.GetBitmap(nIdx,SpdBtn.Glyph); Tag := nIdx; Inc(nIdx); end; end; end; try Frm.ShowModal; finally Result := Frm.ActiveControl.Tag; FreeAndNil(Frm); end; end;
Este código é de minha autoria, veja se te serve. Eu a uso da seguinte maneira:
procedure TForm1.BitBtn1Click(Sender: TObject); begin BitBtn1.Glyph := nil; ImageList1.GetBitmap(GetIndexFromImageList(ImageList1,9,9),BitBtn1.Glyph); end;
Abraços
Gostei + 0
27/09/2006
Mahdak
Anderson, Muito obrigado pelo exemplo, ele caiu como uma luva para o que eu preciso, qualquer coisa a respeito da sua função volto a entrar em contato atravez do tópico...
abraços!
Gostei + 0
27/09/2006
Mahdak
procedure TPrincipal.BitBtn1Click(Sender: TObject); begin BitBtn1.Glyph := nil; Imagens_botoes.GetBitmap(GetIndexFromImageList(Imagelis1,9,9),BitBtn1.Glyph); end;
abraços!
Gostei + 0
27/09/2006
Aloizio Castro
procedure TPrincipal.BitBtn1Click(Sender: TObject); var nIndex : Integer; begin nIndex := GetIndexFromImageList(Imagens_botoes,9,9); BitBtn1.Glyph := nil; Imagens_botoes.GetBitmap(nIndex,BitBtn1.Glyph); BitBtn1.Caption := IntToStr(nIndex); end;
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)