如题。谢谢了!

解决方案 »

  1.   

    第一步,设置listbox的style属性为lbOwnerDrawFixed
    第二步,
    procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer;
      Rect: TRect; State: TOwnerDrawState);
    begin
    listbox1.Canvas.Brush.Color:=clyellow;//当然我这儿设置的是黄色,你也可以换成其它颜色
    ListBox1.Canvas.FillRect(rect);
    ListBox1.Canvas.TextOut(rect.Left+3,rect.Top+3,ListBox1.Items[index]);
    end;
      

  2.   

    这样的话似乎所有的Item都是一样的颜色。但我想做成蓝白相间的效果,请问该怎么实现?
      

  3.   

    procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer;
      Rect: TRect; State: TOwnerDrawState);
    begin
    if odSelected in state then
       begin
       listbox1.Canvas.Brush.Color:=clred;
       ListBox1.Canvas.FillRect(rect);
       ListBox1.Canvas.TextOut(rect.Left+3,rect.Top+3,ListBox1.Items[index]);
       end else
    if (index mod 2)=1 then
    listbox1.Canvas.Brush.Color:=clblue
    else
    listbox1.Canvas.Brush.Color:=clwhite;
    ListBox1.Canvas.FillRect(rect);
    ListBox1.Canvas.TextOut(rect.Left+3,rect.Top+3,ListBox1.Items[index]);
    end;
      

  4.   

    谢谢!真是麻烦你了,昨天也是。请问if odSelected in state这个判断是做什么用的
      

  5.   

    难道现在的人都不看Delphi的Demos吗?
    Demos\DelphiWin32\VCLWin32\CustomDraw