自绘ListBox的两种效果
本文利用Listbox自绘实现了两种特殊效果(见图),左边的风格是自己突然灵感触发想到的,右边的风格来自"C++ Builder 研究"的一个帖子,老妖用BCB实现了,这里则用Delphi实现它。
演示图片:
//--------------------------------------------------------------------------
unit DrawListItem;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ImgList, jpeg, ExtCtrls;
type
TForm1 = class(TForm)
lsbRight: TListBox;
ImageList1: TImageList;
StaticText1: TStaticText;
lsbLeft: TListBox;
imgHouse: TImage;
imgHouseGray: TImage;
procedure FormCreate(Sender: TObject);
procedure lsbRightDrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
procedure lsbRightClick(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure lsbLeftDrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
private
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
{========================================================================
DESIGN BY : 彭国辉
DATE: 2004-11-29
SITE: http://kacarton.yeah.net/
BLOG: http://blog.csdn.net/nhconch
EMAIL: kacarton#sohu.com
;
lsbRight.Items.Add(' to do begin
lsbRight.Items.Add('ListBox Items of ' + IntTostr(i) + #13'Second of '
+ IntToStr(i) + #13'Third of ' + IntToStr(i));
end;
lsbLeft.Style := lbOwnerDrawFixed;
lsbLeft.Ctl3D := false;
lsbLeft.ItemHeight := ;
lsbLeft.Items.Add('编程手札');
lsbLeft.Items.Add('My Developer Knowledge Base');
lsbLeft.Items.Add('站长:天蝎蝴蝶');
lsbLeft.Items.Add('http://blog.csdn.net/nhconch');
end;
procedure TForm1.lsbRightDrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
var
strTemp: String;
begin
, Rect.Top + ,
Rect.Right - , Rect.Bottom - , , );
, Rect.Top + ,
Rect.Right - , Rect.Bottom - , , );
, Rect.Top + ,
Rect.Right - , Rect.Bottom - , , );
,
Rect.top + (lsbRight.ItemHeight - ImageList1.Height) div , Index, true);
+ , Rect.Top + , Length(strTemp));
lsbRight.Canvas.TextOut(Rect.Left + + , Rect.Top + ,
Copy(strTemp, , Pos));
lsbRight.Canvas.TextOut(Rect.Left + + , Rect.Top + ,
Copy(strTemp, Pos, Length(strTemp)));
end;
procedure TForm1.lsbRightClick(Sender: TObject);
begin
StaticText1.Caption := ' ' + lsbRight.Items.Strings[lsbRight.ItemIndex];
end;
procedure TForm1.FormShow(Sender: TObject);
begin
lsbRight.ItemIndex := ;
lsbRight.Repaint();
lsbLeft.ItemIndex := ;
lsbLeft.Repaint();
end;
procedure TForm1.lsbLeftDrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
var
r: TRect;
begin
with lsbLeft.Canvas do begin
, Rect.Top+, Rect.Right-, Rect.Bottom-);
RoundRect(r.Left, r.Top, r.Right, r.Bottom, , );
,
r.Top + , imgHouse.Picture.Graphic)
else ,
r.Top + , imgHouseGray.Picture.Graphic);
;
Brush.Style := bsSolid;
if (odSelected in State) then ; //计算文字顶点位置,(水平居中,DT_CENTER不可用)
DrawText(Handle, PChar(TListBox(Control).Items.Strings[Index]), -1, r
, DT_CENTER or DT_END_ELLIPSIS{ or DT_WORDBREAK});
//画焦点虚框,当系统再绘制时,变成XOR运算,从而达到擦除焦点虚框的目的
if(odFocused in State) then DrawFocusRect(Rect);
end;
end;
end.
http://blog.csdn.net/nhconch/article/details/205127
自绘ListBox的两种效果的更多相关文章
- Javscript轮播 支持平滑和渐隐两种效果(可以只有两张图)
原文:Javscript轮播 支持平滑和渐隐两种效果(可以只有两张图) 先上两种轮播效果:渐隐和移动 效果一:渐隐 1 2 3 4 效果二:移动 1 2 3 4 接下来,我们来大致说下整个轮播的思 ...
- Javascript轮播 支持平滑和渐隐两种效果
Javascript轮播 支持平滑和渐隐两种效果 先上两种轮播效果:渐隐和移动 效果一:渐隐 1 2 3 4 效果二:移动 1 2 3 4 接下来,我们来大致说下整个轮播的思路: 一.先来看简单的 ...
- Javascript轮播 支持平滑和渐隐两种效果(可以只有两张图)
先上两种轮播效果:渐隐和移动 效果一:渐隐 1 2 3 4 效果二:移动 1 2 3 4 接下来,我们来大致说下整个轮播的思路: 一.先来看简单的,移动的,先上来一个图----移动效果图: 说明: ...
- 设置a标签,实现点击跳转页面的两种效果
设置a标签,实现点击跳转页面 这个问题,主要是设置a标签的属性target,下面对target属性进行描述: 跳转在同一个窗口 1,target="_self", 它使得目标文档 ...
- Android 两种方式实现类似水波扩散效果
原文链接 https://mp.weixin.qq.com/s/M19tp_ShOO6esKdozi7Nlg 两种方式实现类似水波扩散效果,先上图为敬 自定义view实现 动画实现 自定义view实现 ...
- Android 文字自动滚动(跑马灯)效果的两种实现方法[特别好使]
有时候在xml中写的跑马灯效果不滚动:原因有以下 Android系统中TextView实现跑马灯效果,必须具备以下几个条件: 1.android:ellipsize=”marquee” 2.TextV ...
- Activity透明/半透明效果的设置transparent(两种实现方法)
两种方法实现Activity透明/半透明效果的设置,代码思路很有调理,感兴趣的朋友可以参考下,希望本文可以帮助到你 方法一:res/values文件夹下建立styles.xml: 复制代码代码如下 ...
- OpenCV3.4两种立体匹配算法效果对比
以OpenCV自带的Aloe图像对为例: 1.BM算法(Block Matching) 参数设置如下: ) + ) & -; cv::Ptr<cv::StereoBM> b ...
- OC可点击的两种轮播图效果
基本上,每一个APP都有一个轮播图的效果展示,一般都是用来展示图片的一些信息,然后可以点击查看或购买,所以在此我将这种轮播图进行了一个类的封装,效果包含两种形式:第一种,来回轮转样式,第二种,一个方向 ...
随机推荐
- Python之路Day10
本节主要内容:memcache&redis.RabbitMQ.twisted框架 1. memcache&redis 1.1 memcache Memcached 是一个高性能的分布式 ...
- Android 代码设置密码输入框内容的显示/隐藏
//内容可见 mEtPassword.setTransformationMethod(HideReturnsTransformationMethod.getInstance()); //内容不可见 m ...
- 【HTTP 2】HTTP/2 协议概述(HTTP/2 Protocol Overview)
前情提要 在上一篇文章<[HTTP 2.0] 简介(Introduction)>中,我们简单介绍了 HTTP 2. 在本篇文章中,我们将会了解到 HTTP 2 协议概述部分的内容. HTT ...
- 【行业干货】2013中国零售商排名 - 课程公告板 - 京东内部论坛 - Powered by Discuz!
[行业干货]2013中国零售商排名 - 课程公告板 - 京东内部论坛 - Powered by Discuz! [行业干货]2013中国零售商排名 [复制链接] bjpanzhoulan ...
- [置顶] 如何判断两个IP大小关系及是否在同一个网段中
功能点 判断某个IP地址是否合法 判断两个IP地址是否在同一个网段中 判断两个IP地址的大小关系 知识准备 IP协议 子网掩码 Java 正则表达式 基本原理 IP地址范围 0.0.0.0- 255 ...
- .yml是什么文件
YAML(IPA: /ˈjæməl/,尾音类似camel骆驼)是一个可读性高,用来表达资料序列的编程语言.YAML参考了其他多种语言,包括:XML.C语言.Python.Perl以及电子邮件格式RFC ...
- SRM 577 Div II Level Two: EllysRoomAssignmentsDiv2
题目来源: http://community.topcoder.com/tc?module=ProblemDetail&rd=15497&pm=12521 这个问题要注意的就是只需要直 ...
- PHP - 防止 XSS(跨站脚本攻击)
<?PHP /** * @blog http://www.phpddt.com * @param $string * @param $low 安全别级低 */ function clean_xs ...
- MYSQL中delete删除多表数据与删除关联数据
在mysql中删除数据方法有很多种,最常用的是使用delete来删除记录,下面我来介绍delete删除单条记 录与删除多表关联数据的一些简单实例. 1.delete from t1 where 条件 ...
- java组装json和提取一个json的例子
package jsonparsed; import net.sf.json.JSONException; import net.sf.json.JSONObject; import net.sf.j ...