我使用delphi中使用了tbsskinlistbox控件制作了一个列表,如图:
但是我想实现下边的这种感觉,就是说把文字部分变成两行:
应该怎么实现呢,谢谢

解决方案 »

  1.   

    对tbsskinlistbox没研究,帮不上忙,帮UP
      

  2.   

    这个tbsskinlistbox没有用过,不过就是算用TListBox作到这个效果也是比较简单,重画就好了
      

  3.   

    用Delphi自带TListBox实现你图上的效果,写了好久。你自己看看,这里面用到一些API,不懂的看看Delphi帮助吧.procedure TForm1.FormCreate(Sender: TObject);
    begin
      ListBox1.Style := lbOwnerDrawVariable; //自己画每一项,项高度可调
      ListBox1.ItemHeight := 30;
    end;procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer;
      Rect: TRect; State: TOwnerDrawState);
    var
      ImgRect, CalcRect: TRect;
      Cnvs: TCanvas;
      B: TBitmap;
      S: string;
      H: Integer;
      FmtExt: Integer;
    begin
      Cnvs := ListBox1.Canvas;
      ImgRect := Rect;
      ImgRect.Right := ImgRect.Left + (ImgRect.Bottom - ImgRect.Top); //画图区域  if odSelected in State then
      begin
        Cnvs.Brush.Color := clSkyBlue;
        Cnvs.Pen.Color := clNavy;
      end
      else
      begin
        Cnvs.Brush.Color := ListBox1.Color;
        Cnvs.Pen.Color := ListBox1.Color;
      end;
      Cnvs.Brush.Style := bsSolid;
      Cnvs.Rectangle(Rect);  Cnvs.Brush.Style := bsClear;
      if ImageList.Count > 0 then
      begin
        B := TBitmap.Create;
        try
          ImageList.GetBitmap(0, B);
          B.PixelFormat := pf24bit;
          B.Transparent := True;
          InflateRect(ImgRect, -2, -2);
          Cnvs.StretchDraw(ImgRect, B);
        finally
          B.Free;
        end;
      end;  Rect.Left := ImgRect.Right;
      CalcRect := Rect;
      S := ListBox1.Items[Index];
      Cnvs.Font.Assign(ListBox1.Font);
      DrawText(Cnvs.Handle, PChar(S), -1,
        CalcRect, DT_WORDBREAK or DT_CALCRECT); //算出高度为了垂直居中
      H := Abs(CalcRect.Top - CalcRect.Bottom); //高度-->i
      H := Abs(Rect.Top - Rect.Bottom) - H; //画布提供的高度与实际要的高度之差-->i
      if H > 0 then
      begin
        Inc(Rect.Top, H div 2);
        Inc(Rect.Bottom, H div 2);
        FmtExt := 0;
      end
      else
        FmtExt := DT_EDITCONTROL; //画不完整的就不画了
      DrawText(Cnvs.Handle, PChar(S), -1,
        Rect, DT_WORDBREAK or FmtExt); //垂直调整居中以后画出文字
    end;
      

  4.   

    太感谢您了,我好好看看,谢谢了,还有一个问题,用一个数组变量动态添加数据的时候,添加完毕后想得到选中项的数据。比如,一个数组(id,userid,username)三项,添加完毕后只显示出来USERNAME,但是我想让他调用的时候可以调用这项的ID,应该如何实现呢?
      

  5.   

    我看了一个例子:他是使用treeview实现的,他在数组中设定了一个TTreeNode的变量,他的实现方法如下:例如数组变量名称为: 
     Puser = ^user;
      user = record
          ID              :Integer;    
          Name            :String[40]; 
          userName            :String[40];   
          Node            :TTreeNode;
          AThread         :TIdPeerThread;
      end;他在实现的时候调用的是:puser(treeview.Selected.Data).ID来调用的。那在使用LISTBOX应该如何实现呢?
      

  6.   

     blazingfire    帮帮忙吧
      

  7.   

    如果代码是Integer型,直接在加的时候把ID强制转化为ID加进去,取的时候再强制转化为Integer就可以了
    加:
    ListBox1.Items.AddObject(UserName, TObject(ID));
    取:
    var
      i: Integer;
    begin
      //如取名字为“blazingfire”的ID就可以这样了
      i := ListBox1.Items.IndexOf('blazingfire');
      if i > -1 then
      begin
        i := Integer(ListBox1.Items.Objects[i]);//强制转化为Integer
        ShowMessage('blazingfire的ID为:'+IntToStr(i));
      end
      else
        ShowMessage('没有找到!');
    end;
    以上代码随手写了,具体的你要自己调一下
      

  8.   

    呵呵,分,我给你加分;
    怎么读取当前选中项目的名字为:blazingfire i := ListBox1.Items.IndexOf('这里是怎么读取呢'); 
    解决后一定给您加分
      

  9.   

    tbsskinlistbox在哪里,我来接分的