在listbox框里有好几项,点击listbox里任一项时,显示的是蓝颜色的条子,怎样才能把蓝颜色的条子变成红颜色的条子。

解决方案 »

  1.   

    在procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer;
      Rect: TRect; State: TOwnerDrawState);
    beginend;
    中写代码自己画
      

  2.   

    在procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer;
      Rect: TRect; State: TOwnerDrawState);
    beginend;
    中写代码自己画
      

  3.   

    将listbox的style改写为lbOwnerDrawFixed,并在drawitem中写如下代码procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer;
      Rect: TRect; State: TOwnerDrawState);
    begin
      Listbox1.Canvas.Font.Color := clWindowText;
      Listbox1.Canvas.Brush.Color := clWindow;
      if listbox1.Selected[Index] then
      begin
        Listbox1.Canvas.Font.Color := clWhite;
        Listbox1.Canvas.Brush.Color := clRed;
      END;
      listbox1.Canvas.FillRect(Rect);
      listbox1.canvas.TextRect(Rect,Rect.left+2, Rect.Top+2, listbox1.Items[Index]);
    end;