ImageVerifierCode 换一换
格式:DOCX , 页数:10 ,大小:17.07KB ,
资源ID:1325872      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/1325872.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(delphi listview自绘图形显示进度条 分颜色显示.docx)为本站会员(b****1)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

delphi listview自绘图形显示进度条 分颜色显示.docx

1、delphi listview自绘图形显示进度条 分颜色显示delphi listview自绘图形显示进度条 分颜色显示 delphi listview自绘图形显示进度条 分颜色显示2011-05-30 10:31delphi listview自绘图形显示进度条 自画TlistView带进度条的Item TListView的Item条一般是由系统自画的,但电驴就实现了自画,使之看起来很漂亮,我们用DELPHI也可以实现! 首先要引用CommCtrl单元,这是TListView底层控制单元:uses CommCtrl; /画状态条procedure DrawSubItem(LV: TListVi

2、ew; Item: TListItem; SubItem: Integer; Prosition: Single; Max, Style: Integer; IsShowProgress: Boolean; DrawColor: TColor = $00005B00; FrameColor: TColor = $00002F00);/获取SubItem的区域 function GetItemRect(LV_Handle, iItem, iSubItem: Integer): TRect; var Rect: TRect; begin ListView_GetSubItemRect(LV_Han

3、dle, iItem, iSubItem, LVIR_LABEL, Rect); Result := Rect; end;var PaintRect, r: TRect; i, iWidth, x, y: integer; S: string;begin try with lv do begin /LockPaint := True; PaintRect := GetItemRect(LV.Handle, Item.Index, SubItem); r := PaintRect;/ if SubItem = DrawSubItem then Begin /这一段是算出百分比 if Prosit

4、ion >= Max then Prosition := 100 else if Prosition <= 0 then Prosition := 0 else Prosition := Round(Prosition / Max) * 100); if (Prosition = 0) and (not IsShowProgress) then begin /如果是百分比是0,就直接显示空白 Canvas.FillRect(r); end else begin /先直充背景色 Canvas.FillRect(r); Canvas.Brush.Color := Color;/ Can

5、vas.FillRect(r); /画一个外框 InflateRect(r, -2, -2); Canvas.Brush.Color := FrameColor; /$00002F00; Canvas.FrameRect(R); Canvas.Brush.Color := Color; InflateRect(r, -1, -1);/ Canvas.FillRect(r); InflateRect(r, -1, -1); /根据百分比算出要画的进度条内容宽度 iWidth := R.Right - Round(R.Right - r.Left) * (100 - Prosition) / 10

6、0); case Style of 0: /进度条类型,实心填充 begin Canvas.Brush.Color := DrawColor; r.Right := iWidth; Canvas.FillRect(r); end; 1: /进度条类型,竖线填充 begin i := r.Left; while i < iWidth do begin Canvas.Pen.Color := Color; Canvas.MoveTo(i, r.Top); Canvas.Pen.Color := DrawColor; canvas.LineTo(i, r.Bottom); Inc(i, 3);

7、 end; end; end;/画好了进度条后,现在要做的就是显示进度数字了 Canvas.Brush.Style := bsClear; if Prosition = Round(Prosition) then S := Format(%d%, Round(Prosition) else S := FormatFloat(#0.0, Prosition); with PaintRect do begin x := Left + (Right - Left + 1 - Canvas.TextWidth(S) div 2; y := Top + (Bottom - Top + 1 - Canva

8、s.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.Li

9、stView1CustomDrawItem( 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);

10、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

11、, 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.Can

12、vas, 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); /这个地方你可以根据自己的要求设置成想要的颜色,实现突出显示 LV.Canvas.Font.Color := clBtnTe

13、xt; /查看是否是被选中 if Item.Selected then begin if cdsFocused in State then begin LV.Canvas.Brush.Color := $00ECCCB9; / /clHighlight; end else begin LV.Canvas.Brush.Color := $00F8ECE5; /clSilver; end; end else begin if (Item.Index mod 2) = 0 then LV.Canvas.Brush.Color := clWhite else LV.Canvas.Brush.Color

14、 := $00F2F2F2; end; LV.Canvas.FillRect(BoundRect); /初始化背景 for i := 0 to LV.Columns.Count - 1 do begin /获取SubItem的Rect ListView_GetSubItemRect(LV.Handle, Item.Index, i, LVIR_LABEL, Rect); case LV.Columnsi.Alignment of taLeftJustify: TextFormat := 0; taRightJustify: TextFormat := DT_RIGHT; taCenter: T

15、extFormat := DT_CENTER; end; case i of 0: /画Caption,0就是表示Caption,这不是Subitems0 begin/先画选择框与图标 Draw_CheckBox_ImageList(BoundRect, LV.Canvas, Item.Checked);/再画Caption的文字 InflateRect(Rect, -(5 + ImageList_Stats.Width), 0); /向后移3个像素,避免被后面画线框时覆盖 DrawText( LV.Canvas.Handle, PCHAR(Item.Caption), Length(Item

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1