在listbox中,当我选了一条记录后,记录的背景色 是深蓝色的,我如何把颜色变成红色?

解决方案 »

  1.   

    将ListBox 的Style属性设置为lbOwnerDrawFixed
    在其OnDrawItem事件中编写代码如下:(
    我实现了加红选中项的功能,但却没有将非选中项显示出来,
    我忘记了一些东西,你自己琢磨看看吧!
    )procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer;
      Rect: TRect; State: TOwnerDrawState);
    begin
    if odSelected in state then
    begin
      (control as TListbox).Canvas.Font.Color:=clwhite;
      (control as TListbox).Canvas.brush.Color:=clred;
    end
    else
      begin
      (control as TListbox).Canvas.Font.Color:=clblack;
      (control as TListbox).Canvas.Brush.Color:=clwhite;
      end;
    (control as TListbox).Canvas.FillRect(Rect);
    (control as TListbox).Canvas.TextRect(Rect,2,2,(control as TListbox).Items[Index]);
    end;
      

  2.   

    1.listbox.style=lbOwnerDrawFixed 2.
    procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer;
      Rect: TRect; State: TOwnerDrawState);
    begin
      if (odSelected in state) then
      begin
        ListBox1.Canvas.Brush.Color:=clBlue;
      ListBox1.Canvas.TextRect(Rect,rect.Left,Rect.Top,ListBox1.Items[index]);
      end;
    end;
      

  3.   

    procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer;
      Rect: TRect; State: TOwnerDrawState);
    begin
     if odSelected in state then
     begin
      listbox1.Canvas.Font.Color:=clwhite;
      listbox1.Canvas.Brush.Color:=clred;
     end
     else
     begin
     listbox1.Canvas.Font.Color:=clblack;
     listbox1.Canvas.Brush.Color:=clwhite;
     end;
    end;
      

  4.   

    用了delphi迷的方法只能实现了加红选中项的功能,但却没有将非选中项显示出来,不知道该如何写啊