Delphi - 在ListView中添加一个进度条

时间:2025-02-23 17:36:32
// 相关定义
Type
TListData = Record
FileName: String;
Percent: Integer;
End; PListData = ^TListData; // 需要Use CommCtrl
Function GetSubItemRect(handle, ItemsIndex, SubIndex: Integer): TRect;
Begin
ListView_GetSubItemRect(handle, ItemsIndex, SubIndex, , @Result);
End; Procedure TFormMain.lvw_listCustomDrawSubItem(Sender: TCustomListView; Item: TListItem; SubItem: Integer;
State: TCustomDrawState; Var DefaultDraw: Boolean);
Var
l_Rect: TRect;
l_intPercent: Integer;
Begin
If SubItem = Then
Begin
If Item.Data = Nil Then
Exit;
l_intPercent := PListData(Item.Data).Percent;
// 获取ListView子项的Rect
l_Rect := GetSubItemRect(Item.handle, Item.Index, SubItem);
// 画一条外边框
InflateRect(l_Rect, -, -);
Sender.Canvas.Brush.Color := clBlack;
Sender.Canvas.FrameRect(l_Rect);
// 先填充底色
InflateRect(l_Rect, -, -);
Sender.Canvas.Brush.Color := lvw_list.Color;
Sender.Canvas.FillRect(l_Rect);
// 再根据进度画出完成区域
If l_intPercent = Then
Sender.Canvas.Brush.Color := clGreen
Else
Sender.Canvas.Brush.Color := clPurple;
l_Rect.Right := l_Rect.Left + Floor((l_Rect.Right - l_Rect.Left) * l_intPercent / );
Sender.Canvas.FillRect(l_Rect);
// 恢复笔刷
Sender.Canvas.Brush.Color := lvw_list.Color;
// 关键的一句,屏蔽系统自绘过程
DefaultDraw := False;
End;
End; // 本文来自****博客,转载请标明出处:http: //blog.****.net/kwbin/archive////.aspx

相关文章