如何用程序代码为TImageList控件添加图标,该用add,还是addImage方法麻烦各位高手帮我举例说明。

解决方案 »

  1.   

    procedure LoadIcon(IconPath:string;var ImageList:TImageList);
    var
      sr: TSearchRec;
      FileAttrs: Integer;
      Path:string;
      i : integer;
      BitMap1 : TBitMap;
    begin
      i := 0;
      ImageList.Clear;
      path:=IconPath+'*.bmp';
      if FindFirst(path, 0, sr) = 0 then
      begin
        BitMap1 := TBitMap.Create;
        i := i+1;
        BitMap1.LoadFromFile(IconPath+IntToStr(i)+'.bmp');
        ImageList.Add(BitMap1,nil);
        while FindNext(sr) = 0 do
        begin
          i := i+1;
          try
            BitMap1.LoadFromFile(IconPath+IntToStr(i)+'.bmp');
            ImageList.Add(BitMap1,nil);
          except
            continue;
          end;
        end;
      end;
    end;