发掘ListBox的潜力(二):鼠标拖放插入点提示(2…
2008-04-09 04:22:13来源:互联网 阅读 ()
beginif FDragOverObject = nil then Exit;
with TListBox(FDragOverObject) do begin
if FDragOverItemIndex > -1 then begin
R := ItemRect(FDragOverItemIndex);
R.Bottom := R.Top 4;
end else if Items.Count>0 then begin
R := ItemRect(Items.Count-1);
R.Top := R.Bottom - 4;
end else begin
windows.GetClientRect(Handle, R);
R.Bottom := R.Top 4;
end;
DrawFocusRect(Canvas.Handle, R);
InflateRect(R, -1, -1);
DrawFocusRect(Canvas.Handle, R);
end;
end;
end.
Left = 192
Top = 107
Width = 540
Height = 376
Caption = ''''Form1''''
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = ''''MS Sans Serif''''
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object ListBox1: TListBox
Left = 24
Top = 24
Width = 201
Height = 265
Style = lbOwnerDrawFixed
DragMode = dmAutomatic
ItemHeight = 20
Items.Strings = (
'''' Accept := (Source is TkktLabelListBox) and (TkktLabelListBox(S''''
''''ource).ItemIndex>-1);'''')
TabOrder = 0
OnDragDrop = ListBox1DragDrop
OnDragOver = ListBox1DragOver
end
object ListBox2: TListBox
Left = 264
Top = 24
Width = 233
Height = 265
Style = lbOwnerDrawFixed
DragMode = dmAutomatic
ItemHeight = 20
Items.Strings = (
''''上代码的确可用而且被广泛使用,但它有一个很大的缺点:''''
''''效率大低。因为每次在Listbox中追加、插入或删除一个''''
''''条目时,都要调用此函数重新计算横向滚动条宽度''''
'''',而遍历所有项目和调用TextWidth都是很是很''''
''''耗时的操作。如果用户将条目从当前Listbox拖往另一''''
''''个Listbox,那么用户一个操作将有两''''
''''个Listbox必须重新计算横向滚动条宽度,当Listbox''''
''''内容有上百条的时候,你将明显感觉反应迟缓。''''
'''' OK,现在换个思路。''''
'''' 当追加或插入新条目时,只要判断新内容的Text''''
''''Width是否大于滚动条宽度,如果是调整滚动条宽度''''
''''即可。那么删除呢?是的,遍历是不可避免的,但并不''''
''''是每次删除都需要。可以定义一个变量记录Listbox中''''
''''TextWidth值最大的条目Index,只有删除这个条目时''''
''''才需要遍历,其它时候完全可以不管它。''''
'''' 还有一种情况必须考虑,用户可能会改变''''
''''屏幕字体,这时也必须重新计算横向滚动条宽度。''''
''''跟删除操作一样计算原最大条目的新TextWidth值即可。''''
'''' 如果窗体上有多个Listbox,记录每个Listbox的''''
''''最大条目也是一件很麻烦的事,所以我把它封装起来,''''
''''下面给出完整代码:'''')
TabOrder = 1
OnDragDrop = ListBox1DragDrop
OnDragOver = ListBox1DragOver
end
end
(完)
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
下一篇:delphi2005中文翻译
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash
