自绘ListBox的两种效果

时间:2010-01-30 12:18:34  来源:第二电脑网  作者:第二电脑网

  第二电脑网导读:phi/2007-11-01/24e8ffb5274e273a95bd4a1ae11ac13e.gif" />演示图片:自绘ListBox的效果//--------------------------------------------------------------------------
  正文:本文利用Listbox自绘实现了两种特殊效果(见图),左边的风格是自己突然灵感触发想到的,右边的风格来自"C++ Builder 研究"的一个帖子,老妖用BCB实现了,这里则用Delphi实现它。


演示图片:
自绘ListBox的效果



//--------------------------------------------------------------------------

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

  文章为作者原创,转载前请先与本人联系,转载请注明文章出处、保留作者信息,谢谢支持!
=========================================================================}


procedure TForm1.FormCreate(Sender: TObject);
var
i: integer;
begin
  lsbRight.Style := lbOwnerDrawFixed;
  lsbRight.Ctl3D := false;
  lsbRight.ItemHeight := 50;
  lsbRight.Items.Add('C++ Builder 研究 致力于BCB的学习探讨和研究'#13'ccrun(老妖)');
  lsbRight.Items.Add('编程手札 My Developer Knowledge Base'#13'http://blog.csdn.net/nhconch'#13'天蝎蝴蝶');
  for i:=3 to 10 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 := 90;
  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
  //文字颜色
    lsbRight.Canvas.Font.Color := clBlack;
  //设置背景颜色并填充背景
    lsbRight.Canvas.Brush.Color := clWhite;
  lsbRight.Canvas.FillRect (Rect);
  //设置圆角矩形颜色并画出圆角矩形
    lsbRight.Canvas.Brush.Color := TColor($00FFF7F7);
  lsbRight.Canvas.Pen.Color := TColor($00131315);
  lsbRight.Canvas.RoundRect(Rect.Left + 3, Rect.Top + 3,
  Rect.Right - 2, Rect.Bottom - 2, 8, 8);
  //以不同的宽度和高度再画一次,实现立体效果
"自绘ListBox的两种效果"由第二电脑网原创提供,转载请注明:http://www.002pc.com/master/College/Language/Delphi/12648.html


关键字:

关于《自绘ListBox的两种效果》文章的评论

站内搜索: 高级搜索

热门搜索: Windows style 系统 tr IP QQ CPU 安装 function 注册 if td