请问有哪个控件可以像QQ那样,在listbox的item前面加图片吗?

解决方案 »

  1.   

    用TREEVIEW不是很好吗?可以和IMAGELIST共同使用
      

  2.   

    楼上的朋友你好,但是我不想要treeview那些树的虚线阿。有没有办法呢?
      

  3.   

    应该是没有  要是有了 不就象word一样强大了?
      

  4.   

    可以给ListBox的加载重绘事件。OnDrawItem来修改Item。以下是CnWizard的ListBox重绘的代码,http://www.cnvcl.orgprocedure TCnWizConfigForm.lbWizardsDrawItem(Control: TWinControl;
      Index: Integer; Rect: TRect; State: TOwnerDrawState);
    var
      ListBox: TListBox;
      Canvas: TCanvas;
      ARect: TRect;
      R: TRect;
      Wizard: TCnBaseWizard;
      x, y: Integer;
      Bmp: TBitmap;
    begin
      if not (Control is TListBox) then Exit;
      ListBox := TListBox(Control);
      Wizard := TCnBaseWizard(ListBox.Items.Objects[Index]);  // 创建临时位图以消除闪烁
      Bmp := TBitmap.Create;
      try
        Bmp.PixelFormat := pf24bit;
        Bmp.Width := RectWidth(Rect);
        Bmp.Height := RectHeight(Rect);
        ARect := Bounds(0, 0, Bmp.Width, Bmp.Height);    R.Left := ARect.Left + 4;
        R.Right := ARect.Right - 5;
        R.Top := ARect.Top + 2;
        R.Bottom := ARect.Bottom - 2;    Canvas := Bmp.Canvas;
        Canvas.Font.Assign(ListBox.Font);
        Canvas.Brush.Style := bsSolid;
        Canvas.Brush.Color := ListBox.Color;
        Canvas.FillRect(ARect);
        Canvas.Brush.Color := csShadowColor;
        Canvas.RoundRect(R.Left + 1, R.Top + 1, R.Right + 1, R.Bottom + 1, 8, 8);    if odSelected in State then
        begin
          Canvas.Brush.Color := csSelectedColor;
          Canvas.Font.Color := clBlue;
        end
        else if FActives[Index] then
        begin
          Canvas.Brush.Color := csNormalColor;
          Canvas.Font.Color := clBlack;
        end
        else
        begin
          Canvas.Brush.Color := csNormalColor;
          Canvas.Font.Color := clGray;
        end;
        Canvas.RoundRect(R.Left, R.Top, R.Right, R.Bottom, 8, 8);    //这里加载图标,有些大了点,根据自己需要修改好高度
        if Wizard.Icon <> nil then
          Canvas.Draw(R.Left + 4, R.Top + (R.Bottom - R.Top - Wizard.Icon.Height) div 2, Wizard.Icon);    x := R.Left + 42;
        y := R.Top + 2;    //如下输出文字,Item本身的文字输出已经作废。也是根据情况自己修改……
        Canvas.TextOut(x, y, SCnWizardNameStr + Wizard.WizardName);
        Inc(y, 12);
        if FActives[Index] then
          Canvas.TextOut(x, y, SCnWizardStateStr + SCnWizardActiveStr)
        else
          Canvas.TextOut(x, y, SCnWizardStateStr + SCnWizardDisActiveStr);
        Inc(y, 12);
        Canvas.TextOut(x, y, SCnWizardShortCutStr + ShortCutToText(FShortCuts[Index]));    BitBlt(ListBox.Canvas.Handle, Rect.Left, Rect.Top, Bmp.Width, Bmp.Height,
          Canvas.Handle, 0, 0, SRCCOPY);
      finally
        Bmp.Free;
      end;
    end;
      

  5.   

    如果最方便加载图片,TreeView和ListView都可以。TreeView自然可以把虚线去掉,很简单。ListView的详细列表方式就可以。如果你要ListBox,就是重绘Item了。自己权衡。
      

  6.   

    谢谢楼上的兄弟了。问题解决了,原来TreeView去掉虚线真的很简单,呵呵。
    给你分了。