本文利用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的两种效果的更多相关文章

  1. Javscript轮播 支持平滑和渐隐两种效果(可以只有两张图)

    原文:Javscript轮播 支持平滑和渐隐两种效果(可以只有两张图) 先上两种轮播效果:渐隐和移动   效果一:渐隐 1 2 3 4 效果二:移动 1 2 3 4 接下来,我们来大致说下整个轮播的思 ...

  2. Javascript轮播 支持平滑和渐隐两种效果

    Javascript轮播 支持平滑和渐隐两种效果 先上两种轮播效果:渐隐和移动   效果一:渐隐 1 2 3 4 效果二:移动 1 2 3 4 接下来,我们来大致说下整个轮播的思路: 一.先来看简单的 ...

  3. Javascript轮播 支持平滑和渐隐两种效果(可以只有两张图)

    先上两种轮播效果:渐隐和移动   效果一:渐隐 1 2 3 4 效果二:移动 1 2 3 4 接下来,我们来大致说下整个轮播的思路: 一.先来看简单的,移动的,先上来一个图----移动效果图: 说明: ...

  4. 设置a标签,实现点击跳转页面的两种效果

    设置a标签,实现点击跳转页面 这个问题,主要是设置a标签的属性target,下面对target属性进行描述: 跳转在同一个窗口 1,target="_self",  它使得目标文档 ...

  5. Android 两种方式实现类似水波扩散效果

    原文链接 https://mp.weixin.qq.com/s/M19tp_ShOO6esKdozi7Nlg 两种方式实现类似水波扩散效果,先上图为敬 自定义view实现 动画实现 自定义view实现 ...

  6. Android 文字自动滚动(跑马灯)效果的两种实现方法[特别好使]

    有时候在xml中写的跑马灯效果不滚动:原因有以下 Android系统中TextView实现跑马灯效果,必须具备以下几个条件: 1.android:ellipsize=”marquee” 2.TextV ...

  7. Activity透明/半透明效果的设置transparent(两种实现方法)

    两种方法实现Activity透明/半透明效果的设置,代码思路很有调理,感兴趣的朋友可以参考下,希望本文可以帮助到你   方法一:res/values文件夹下建立styles.xml: 复制代码代码如下 ...

  8. OpenCV3.4两种立体匹配算法效果对比

    以OpenCV自带的Aloe图像对为例:     1.BM算法(Block Matching) 参数设置如下: ) + ) & -; cv::Ptr<cv::StereoBM> b ...

  9. OC可点击的两种轮播图效果

    基本上,每一个APP都有一个轮播图的效果展示,一般都是用来展示图片的一些信息,然后可以点击查看或购买,所以在此我将这种轮播图进行了一个类的封装,效果包含两种形式:第一种,来回轮转样式,第二种,一个方向 ...

随机推荐

  1. javascript 学习随笔2

    <html> <head> <script type="text/javascript"> function writeText(txt) { ...

  2. django-model-utils

    一个普通例子: todos = Todo.objects.filter(owner=request.user).filter(is_done=False).filter(priority=1) 弊端: ...

  3. Week13(12月2日):又到了那个点,期末了~~~~

    Part I:提问 =========================== 1.ASP.NET MVC是微软.NET平台上的一个(      ). A.语言    B.集成开发环境    C.Web开 ...

  4. larbin是一种开源的网络爬虫/网络蜘

    larbin是一种开源的网络爬虫/网络蜘蛛,由法国的年轻人 Sébastien Ailleret独立开发.larbin目的是能够跟踪页面的url进行扩展的抓取,最后为搜索引擎提供广泛的数据来源.Lar ...

  5. Linux c c++ 开发调试技巧

    看到一篇介绍 linux c/c++ 开发调试技巧的文章,感觉挺使用,哪来和大家分享. 通向 UNIX 天堂的 10 个阶梯Author: Arpan Sen, 高级技术人员, Systems Doc ...

  6. (step7.2.4)hdu 2674(N!Again——简单数论)

    题目大意:输入一个整数n,输出N! mod 2009 的结果. 解题思路: 1)任意数  n = ( n / 2009) * 2009 + n % 2009 2)40!  mod 2009  等于 2 ...

  7. Amazon的AWS账单看起来不是很方便

    发了一个PDF格式的收据,只写了收取的费用,EC2下面的明细没有. DetailAmazon Simple Notification Service $0.00Charges $0.00Estimat ...

  8. DHTMLX系列组件的学习笔记

    <link rel="stylesheet" type="text/css" href="codebase/skins/dhtmlxeditor ...

  9. Android:Notification的生成与取消

    MainActivity.java: package com.example.notificationdemo; import android.app.Activity; import android ...

  10. gethostbyname()函数说明

    gethostbyname()函数说明——用域名或主机名获取IP地址 包含头文件    #include <netdb.h>    #include <sys/socket.h> ...