很简单的ListBox自画
最终效果图:Lazarus也一样
ListBox的两个设置:
自画事件:ListBox1DrawItem
procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState); begin With ListBox1.Canvas Do Begin Brush.Color := $00FF9184; //设置背景颜色并填充背景 FillRect(Rect); Brush.Color := clBlack; //设置圆角矩形颜色并画出圆角矩形 Pen.Color := $00131315; RoundRect(Rect.Left + 3, Rect.Top + 3, Rect.Right - 3, Rect.Bottom - 3, 5, 5); Brush.Color := $00A2F9F0; Pen.Color := clInfoBk; RoundRect(Rect.Left + 3, Rect.Top + 3, Rect.Right - 6, Rect.Bottom - 6, 5, 5); //以不同的宽度和高度再画一次,实现立体效果 If (odSelected In State) Then {//如果是当前选中项} Begin Brush.Color := $00BBBBFF; //以不同的背景色画出选中项的圆角矩形 RoundRect(Rect.Left + 3, Rect.Top + 3, Rect.Right - 3, Rect.Bottom - 3, 5, 5); //选中项的文字颜色 End; ImageList1.Draw(ListBox1.Canvas, Rect.Left + 6, //画出图标 Rect.Top , index, true); Font.Color := $00A25155; //分别绘出各行文字 TextOut(Rect.Left + ImageList1.Width + 10, Rect.Top + 4,ListBox1.Items[index]); Font.Color := $0F01630E; TextOut(Rect.Left + ImageList1.Width + 15, Rect.Top - (ListBox1.Font.Height - 4) + 2, '语言: ' ); TextOut(Rect.Left + ImageList1.Width + 10, Rect.Top - (ListBox1.Font.Height - 4) * 2, '文章总数: ' ); If (odFocused In State) Then ListBox1.Canvas.DrawFocusRect(Rect); End; End;
先要设置 ImageList1的宽和高,再导入图片,否则,图片会被清空。
测试图标下载:
链接:https://pan.baidu.com/s/1eCLTHlpc06CwH1WL9AgHkw
提取码:83rn
Lazarus也一样
链接:https://pan.baidu.com/s/1teNb8puiVhn_aEKb67Op9g
提取码:chtl
分类:
Delphi7相关
, Delphi2010
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
2021-06-15 uniGUI学习之脱离Delphi直接写ExtJS从入门到精通02Ext.Panel创建后_调用的几种方法(46)
2021-06-15 在线 编译 pascal
2021-06-15 uniGUI学习之脱离Delphi直接写ExtJS从入门到精通01_环境搭建_Helloworld(45)