Delphi中BeginUpdate和EndUpdate作用
来源:互联网 发布:项目进度跟踪软件 编辑:程序博客网 时间:2024/05/18 01:13
许多 Windows 窗体控件(例如,ListView 和 TreeView 控件)实现了 BeginUpdate 和EndUpdate 方法,它们在操纵基础数据或控件属性时取消了控件的重新绘制。通过使用BeginUpdate 和 EndUpdate 方法,您可以对控件进行重大更改,并且避免在应用这些更改时让控件经常重新绘制自身。此类重新绘制会导致性能显著降低,并且用户界面闪烁且不反应。例如,如果您的应用程序具有一个要求添加大量节点项的树控件,则您应该调用 BeginUpdate,添加所有必需的节点项,然后调用 EndUpdate。下面的代码示例显示了一个树控件,该控件用于显示许多个客户的层次结构表示形式及其定单信息。
[C#]
// Suppress repainting the TreeView until all the objects have been created.
TreeView1.BeginUpdate();
// Clear the TreeView.
TreeView1.Nodes.Clear();
// Add a root TreeNode for each Customer object in the ArrayList.
foreach( Customer customer2 in customerArray )
{
TreeView1.Nodes.Add( new TreeNode( customer2.CustomerName ) );
// Add a child TreeNode for each Order object in the current Customer.
foreach( Order order1 in customer2.CustomerOrders )
{
TreeView1.Nodes[ customerArray.IndexOf(customer2) ].Nodes.Add(
new TreeNode( customer2.CustomerName + "." + order1.OrderID ) );
}
}
// Begin repainting the TreeView.
TreeView1.EndUpdate();
[Visual Basic .NET]
' Suppress repainting the TreeView until all the objects have been
created.
TreeView1.BeginUpdate()
' Clear the TreeView
TreeView1.Nodes.Clear()
' Add a root TreeNode for each Customer object in the ArrayList
For Each customer2 As Customer In customerArray
TreeView1.Nodes.Add(New TreeNode(customer2.CustomerName))
' Add a child TreeNode for each Order object in the current Customer.
For Each order1 As Order In customer2.CustomerOrders
TreeView1.Nodes(Array.IndexOf(customerArray, customer2)).Nodes.Add( _
New TreeNode(customer2.CustomerName & "." & order1.OrderID))
Next
Next
' Begin repainting the TreeView.
TreeView1.EndUpdate()
即使在您不希望向控件添加许多对象时,您也应该使用 BeginUpdate 和 EndUpdate 方法。在大多数情况下,您在运行之前将不知道要添加的项的确切个数。因此,为了妥善处理大量数据以及应付将来的要求,您应该总是调用 BeginUpdate 和 EndUpdate 方法。注调用 Windows 窗体控件使用的许多 Collection 类的 AddRange 方法时,将自动为您调用 BeginUpdate 和 EndUpdate 方法。
[C#]
// Suppress repainting the TreeView until all the objects have been created.
TreeView1.BeginUpdate();
// Clear the TreeView.
TreeView1.Nodes.Clear();
// Add a root TreeNode for each Customer object in the ArrayList.
foreach( Customer customer2 in customerArray )
{
TreeView1.Nodes.Add( new TreeNode( customer2.CustomerName ) );
// Add a child TreeNode for each Order object in the current Customer.
foreach( Order order1 in customer2.CustomerOrders )
{
TreeView1.Nodes[ customerArray.IndexOf(customer2) ].Nodes.Add(
new TreeNode( customer2.CustomerName + "." + order1.OrderID ) );
}
}
// Begin repainting the TreeView.
TreeView1.EndUpdate();
[Visual Basic .NET]
' Suppress repainting the TreeView until all the objects have been
created.
TreeView1.BeginUpdate()
' Clear the TreeView
TreeView1.Nodes.Clear()
' Add a root TreeNode for each Customer object in the ArrayList
For Each customer2 As Customer In customerArray
TreeView1.Nodes.Add(New TreeNode(customer2.CustomerName))
' Add a child TreeNode for each Order object in the current Customer.
For Each order1 As Order In customer2.CustomerOrders
TreeView1.Nodes(Array.IndexOf(customerArray, customer2)).Nodes.Add( _
New TreeNode(customer2.CustomerName & "." & order1.OrderID))
Next
Next
' Begin repainting the TreeView.
TreeView1.EndUpdate()
即使在您不希望向控件添加许多对象时,您也应该使用 BeginUpdate 和 EndUpdate 方法。在大多数情况下,您在运行之前将不知道要添加的项的确切个数。因此,为了妥善处理大量数据以及应付将来的要求,您应该总是调用 BeginUpdate 和 EndUpdate 方法。注调用 Windows 窗体控件使用的许多 Collection 类的 AddRange 方法时,将自动为您调用 BeginUpdate 和 EndUpdate 方法。
阅读全文
0 0
- Delphi中BeginUpdate和EndUpdate作用
- BeginUpdate和EndUpdate作用
- BeginUpdate()和EndUpdate()
- TreeView和ListView用到的BeginUpdate()和EndUpdate()的作用
- ListView的BeginUpdate()和EndUpdate()的用处
- UITableView beginUpdate和endUpdate使用的前提
- CPaintDC及其与BeginUpdate、EndUpdate的前因后果
- paip.提升性能---.net listbox 使用BeginUpdate与EndUpdate
- BeginUpdate()
- Delphi 中initialization和finalization的作用
- Delphi中 “@” “^” 符号的作用
- delphi中application.processmessages的作用
- 关于Delphi中Interface的作用
- delphi中application.processmessages的作用
- delphi中application.processmessages的作用
- define中 #和##作用
- Delphi中initialization和finalization
- Delphi中initialization和finalization
- 史上最全设计模式导学目录(完整版)
- SecureCRT常用命令分享 SecureCRT命令大全
- jQuery源码解析--jQuery.noConflict() 函数详解
- ASP 异步加载—不会Ajax也能用
- css-网页聊天窗口对话框
- Delphi中BeginUpdate和EndUpdate作用
- HTML学习笔记CSS
- 解决php报错configure: error: xml2-config not found. Please check your libxml2 installation
- Github简单教程
- java判断某一字符串是否包含另一个字符串
- 逆置、翻转链表/查找单链表的倒数第k个节点/A+B不使用四则运算++ -- 等
- 用eclipse打开一个文件,左边的树怎么自动对应文件
- TestLink学习一:Windows搭建Apache+MySQL+PHP环境
- 如何在Python中实现RFM分析