p; x := Left + (Right - Left + 1 - Canvas.TextWidth(S)) div 2;
y := Top + (Bottom - Top + 1 - Canvas.TextHeight(S)) div 2;
end;
SetBkMode(Canvas.handle, TRANSPARENT);
Canvas.TextRect(PaintRect, x, y, S);
end;
//进度条全部画完,把颜色设置成默认色了
Canvas.Brush.Color := Color;
end
end;
except
end;
end;
上面是画进度条的,现在要给TlistView处理Item重绘的消息,事件是OnCustomDrawItem,需要说明的是,如果想要随心所欲的自画Item,那么就要全部自己来完成,不再需要系统来处理:
procedure TForm1.ListView1CustomDrawItem(
Sender: TCustomListView; Item: TListItem; State: TCustomDrawState;
var DefaultDraw: Boolean);
var
BoundRect, Rect: TRect;
i: integer;
TextFormat: Word;
LV: TListView;
//这个子过程是用来画CheckBox和ImageList的
procedure Draw_CheckBox_ImageList(r: TRect; aCanvas: TCanvas; Checked: Boolean);
var
R1: TRect;
i: integer;
begin
if Sender.Checkboxes then
begin
aCanvas.Pen.Color := clBlack;
aCanvas.Pen.Width := 2;
//画CheckBox外框
aCanvas.Rectangle(r.Left + 2, r.Top + 2, r.Left + 14, r.Bottom - 2);
if Checked then
begin //画CheckBox的勾
aCanvas.MoveTo(r.Left + 4, r.Top + 6);
aCanvas.LineTo(r.Left + 6, r.Top + 11);
aCanvas.LineTo(r.Left + 11, r.Top + 5);
end;
aCanvas.Pen.Width := 1;
end;
//开始画图标
i := PDownLoadListItem(Item.Data)^.StatsImageIndex;
if i > -1 then
begin
//获取图标的RECT
if Boolean(ListView_GetSubItemRect(sender.Handle, item.Index, 0, LVIR_ICON, @R1)) then
begin
ImageList_Stats.Draw(LV.Canvas, R1.Left, R1.Top, i);
if item.ImageIndex > -1 then
LV.SmallImages.Draw(LV.Canvas, R1.Right + 2, R1.Top, item.ImageIndex);
end;
end;
end;
begin
LV := ListView1;
BoundRect := Item.DisplayRect(drBounds);
InflateRect(BoundRect, -1, 0);
//这个地方你可以根据自