是这样的,我用NMFTP控件做了一个上传的小程序,与服务器连接后用ListBox显示服务器上的文件列表,但是显示出来后文件和文件夹不太好区分,我想用图片区分文件和文件夹(象CuteFtp那样),有什么办法吗?????

解决方案 »

  1.   

    用ListBox是可以实现,不过需要用到一些辅助变量,以及画布的功能。下面是我就我之前写的测试代码,临时分析了一下,可能有些问题。还有些代码可能是多余的,:)
    1、首先先将文件夹及文件图标载入到ImageList中。
    2、在列出Ftp文件列表时,根据是文件夹还是文件,生成FolderArray
    3、在ListBox的OnDrawItem写入代码。
    procedure TFrmListBoxTest.LBTestDrawItem(Control: TWinControl;
      Index: Integer; Rect: TRect; State: TOwnerDrawState);
    var tmpBmp:TBitmap;
        ImgIndex :integer;
        DrawX,DrawY:integer;
    begin
      tmpBmp :=TBitmap.Create();
      { FolderArray为动态数组,可在列出文件时生成的标 }
      { 此处为取该图标在ImageList的位置 }
      ImgIndex :=FolderArray[Index]
      IMGLst.GetBitmap(ImgIndex,tmpBmp);
      DrawX :=3;
      DrawY :=Rect.Top+Round(((Rect.Bottom-Rect.Top)-tmpBmp.Height)/2); 
      if (odFocused in State) then
      begin
        { 聚焦时的重画事件 }
        with LBTest.Canvas do
        begin
          Brush.Style :=bsSolid;
          Brush.Color :=RGB(129,154,204);
          //FillRect(Rect);
          Pen.Color :=clBlack;
          RoundRect(Rect.Left,Rect.Top,Rect.Right,Rect.Bottom,4,4);
          Draw(DrawX-1,DrawY-1,tmpBmp);
          Brush.Style :=bsClear;
          Rectangle(DrawX-1,DrawY-1,DrawX+tmpBmp.Width-1,DrawY+tmpBmp.Height-1);
          DrawFocusRect(Rect); 
        end;
      end
      else begin
        { 非聚焦时的重画事件 }
        with LBTest.Canvas do
        begin
          Brush.Style :=bsSolid;
          Brush.Color :=clWhite;
          FillRect(Rect);
          Pen.Color :=clBlack;
          Brush.Style :=bsClear;
          Rectangle(DrawX,DrawY,DrawX+tmpBmp.Width,DrawY+tmpBmp.Height);
          Draw(DrawX,DrawY,tmpBmp);
        end;
      end;
      tmpBmp.Free();
    end;
      

  2.   

    想你这种情况我觉得还是使用树(TreeView)比较好。