当前位置:主页>仓库管理软件> 列表

listbox的底色问题,高手教我! 找简单的财务管理软件

记账软件版1楼: 怎样能将listbox的奇数行和偶数行的底色区分开来?

2楼: procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
begin
with ListBox1.Canvas do
begin
if listbox1.Items[index] = ''10'' then
begin
Font.Color:=clred;
Brush.Color:=clBlue;
end else
begin
Font.Color:=clBlue;
Brush.Color:=clred;
end;
FillRect(Rect);
TextOut(Rect.Left, Rect.Top, listbox1.Items[index]);
end;
end; 如简单的财务管理软件

3楼: 试了一下!好像是不行!

4楼: 帮你顶!

5楼: unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

type
TForm1 = class(TForm)
ListBox1: TListBox;
procedure FormCreate(Sender: TObject);
procedure ListBox1DrawItem(Control: TWinControl; Index: Integer;


Rect: TRect; State: TOwnerDrawState);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
var
i: Integer;
begin
listbox1.Style := lbOwnerDrawVariable;
for i := 0 to 100 - 1 do
begin
listbox1.AddItem(''item'' + Inttostr(i),TObject(i));
end;
end;

procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
begin
with ListBox1.Canvas do
begin
if (Integer(listbox1.Items.Objects[index]) mod 2) = 0 then
begin
Font.Color:=clred;
Brush.Color:=clBlue;
end else
begin
Font.Color:=clBlue;
Brush.Color:=clred;
end;
FillRect(Rect);
TextOut(Rect.Left, Rect.Top, listbox1.Items[index]);
end;
end;

end.

6楼: 明白了没有,这下可以了吧!

记账软件版7楼: 我修改了style属性后就可以了