问一下,我想让listview(带图标)的每一行颜色(底色)不同,如何做?

pbcl 2001-08-07 06:26:43
...全文
154 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
pbcl 2001-08-08
  • 打赏
  • 举报
回复
接收答案了!
ch81 2001-08-08
  • 打赏
  • 举报
回复
我的程序如下,你自己改一下即可。你把画图的代码改为
ListView1.Canvas.Font.Color:=the text color you want
ListView1.Canvas.Pen.Color:=the background color
ListView1.Canvas.Rectangle(X1, Y1, X2, Y2: Integer)
ListView1.Canvas.TextOut(x,y,'text')但要计算好位置
思路是先画一个矩形作为背景,再在上面写字。切记位置要计算好。
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls;
type
TForm1 = class(TForm)
ListView1: TListView;
procedure ListView1CustomDrawItem(Sender: TCustomListView;
Item: TListItem; State: TCustomDrawState; var DefaultDraw: Boolean);
procedure ListView1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
var x1,y1:integer;
implementation
{$R *.dfm}
procedure TForm1.ListView1CustomDrawItem(Sender: TCustomListView;
Item: TListItem; State: TCustomDrawState; var DefaultDraw: Boolean);
var Bitmap:TBitmap;
begin
Bitmap:=TBitmap.Create;
If Item.Caption='Hello' then
begin
Bitmap.LoadFromFile('1.bmp');
ListView1.Canvas.Draw(x1,y1,Bitmap);
Bitmap.FreeImage;
end
else
begin
Bitmap.LoadFromFile('2.bmp');
ListView1.Canvas.Draw(0,0,Bitmap);
x1:=0;//Bitmap.Width;
y1:=Bitmap.Height;
end;
DefaultDraw:=False;
end;
procedure TForm1.ListView1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
if y>y1 then
begin
ShowMessage('Hello');
end;
if y<y1 then
begin
ShowMessage('Baby');
end;
end;
end.
pbcl 2001-08-08
  • 打赏
  • 举报
回复
up,拜托,谁给一段代码,我马上给分!!!
ch81 2001-08-07
  • 打赏
  • 举报
回复
自画,你的还比较简单,只要底色不同即可。我在下面的贴子上的代码可以自画图像
http://www.csdn.net/expert/topic/225/225618.shtm
eDRIVE 2001-08-07
  • 打赏
  • 举报
回复
我的代码很散,不过原理很清楚,就是Nicrosoft所说的。Delphi的HELP可以给你完整的答案
Nicrosoft 2001-08-07
  • 打赏
  • 举报
回复
没有
pbcl 2001-08-07
  • 打赏
  • 举报
回复
具体代码能给一段吗?谢谢!
Nicrosoft 2001-08-07
  • 打赏
  • 举报
回复
自画
pbcl 2001-08-07
  • 打赏
  • 举报
回复
大家帮帮忙!!!

5,385

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧