您现在的位置是: 软件 > 开发者网络 > 程序方舟 > 开发专栏 > DELPHI开发 > 正文
·速成电脑精英(包分配)白领高薪一族从这里开始



-Java套接字编程(下)
-MediaStudio Pro 6.5教程
-三款卸载软件最新试用
-基于Visual C++的Winsock API研究

Delphi中ListBox控件的六种特效
2001-06-12· ·陈立平 ··yesky

上一页  1 2 3 4  下一页


  二、 特殊效果的实现

  在窗体(Form1)上放置5个ListBox,名称分别为ListBox1……ListBox5,将所有ListBox的Style属性设置为lbOwnerDrawVariable;在Form1上添加两个TImageList控件,命名为ImageList1,ImageList2;在ImageList1中装入两个16X16大小的图标;添加两个TButton控件,命名为Button1,Button2;再添加一个TImage控件,命名为Image1。其它操作,见下。

  1. 具有图标及热链接效果的列表框

  在ListBox1的Items属性中添加几个字符串,并在ListBox1的OnDrawItem事件中编写代码如下:


procedure TForm1.ListBox2DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
var
AIcon, BIcon: TIcon;
begin
try
file://从上述ImageList1中装入两个图标
AIcon := TIcon.Create;
BIcon := TIcon.Create;
file://装入图标到AIcon, BIcon
ImageList1.GetIcon(0, AIcon);
ImageList1.GetIcon(1, BIcon);
file://填充绘图区
ListBox1.Canvas.FillRect(Rect);
file://判断ListBox1中的当前重绘项是否被选中,根据状态装入不同的图标
if odSelected in State then
ListBox1.Canvas.Draw(Rect.Left, Rect.Top, AIcon)
else
ListBox1.Canvas.Draw(Rect.Left, Rect.Top, BIcon);
file://输出文字
ListBox1.Canvas.TextOut(Rect.Left + AIcon.Width div 2, Rect.Top + 2, ListBox1.Items[Index]);
finally
AIcon.Free;
BIcon.Free;
end;
end;

注:也可在OnMeasureItem事件中改变列表项的高度。

  2. 具有横向滚动条效果的列表框

  在Form1上Button1的Click事件中书写如下代码:

procedure TForm1.Button1Click(Sender: TObject);
begin
SendMessage(ListBox1.Handle, LB_SETHORIZONTALEXTENT, ListBox1.Width + 30, 0);
end;

具体横向滚动区域的宽度可通过具体计算得出,在此从略。

上一页  1 2 3 4  下一页

【责任编辑:方舟】
【发表评论】【关闭窗口】
■ 相关内容
 Delphi中利用MSCOMM控件进行GPS数据采集
 Delphi中票据凭证的精确打印
 为Windows窗口标题栏添加新按钮
 Delphi利用Windows GDI实现文字倾斜
 Delphi串口通讯的监听
 Delphi数据压缩处理
 Delphi实现NetBIOS广播收发
感谢 访问天极网,如果您觉得该文章涉及版权问题,请看这里!