多线程填写treeview控件(vb.net)__教程 |
|
日期:2007-5-20 1:23:29 人气:59 [大 中 小] |
|
|
|
功能:把选定文件夹下的dll、子文件夹和子文件夹中的dll填写到窗体的treeview控件上。
缺点:窗体简单,代码有些混乱,线程之间的调用可能没有到最优化。
实现:imagelist中的图片需要自己重新定义。
多线程的优点:可以及时响应用户的操作,不至于产生“未响应”的尴尬;设计合理(结合需求)的话,可使软件的性能提高。
多线程的编写:结构合理、注意同步。
以上是我对这个例程和多线程的个人体会,如有不妥之处,还请大家批评指正。
Imports System.IO Public Class Form1 Inherits System.Windows.Forms.Form
#Region " Windows 窗体设计器生成的代码 "
Public Sub New() MyBase.New()
'该调用是 Windows 窗体设计器所必需的。 InitializeComponent()
'在 InitializeComponent() 调用之后添加任何初始化
End Sub
'窗体重写 dispose 以清理组件列表。 Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub
'Windows 窗体设计器所必需的 Private components As System.ComponentModel.IContainer
'注意: 以下过程是 Windows 窗体设计器所必需的 '可以使用 Windows 窗体设计器修改此过程。 '不要使用代码编辑器修改它。 Friend WithEvents TreeView1 As System.Windows.Forms.TreeView Friend WithEvents btnOpenBrower As System.Windows.Forms.Button Friend WithEvents ImageList1 As System.Windows.Forms.ImageList <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() Me.components = New System.ComponentModel.Container Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Form1)) Me.TreeView1 = New System.Windows.Forms.TreeView Me.ImageList1 = New System.Windows.Forms.ImageList(Me.components) Me.btnOpenBrower = New System.Windows.Forms.Button Me.SuspendLayout() ' 'TreeView1 ' Me.TreeView1.Dock = System.Windows.Forms.DockStyle.Left Me.TreeView1.ImageList = Me.ImageList1 Me.TreeView1.Location = New System.Drawing.Point(0, 0) Me.TreeView1.Name = "TreeView1" Me.TreeView1.Size = New System.Drawing.Size(376, 581) Me.TreeView1.TabIndex = 0 ' 'ImageList1 ' Me.ImageList1.ImageSize = New System.Drawing.Size(16, 16) Me.ImageList1.ImageStream = CType(resources.GetObject("ImageList1.ImageStream"), System.Windows.Forms.ImageListStreamer) Me.ImageList1.TransparentColor = System.Drawing.Color.Transparent ' 'btnOpenBrower ' Me.btnOpenBrower.Location = New System.Drawing.Point(408, 64) Me.btnOpenBrower.Name = "btnOpenBrower" Me.btnOpenBrower.Size = New System.Drawing.Size(96, 23) Me.btnOpenBrower.TabIndex = 1 Me.btnOpenBrower.Text = "Open Brower" ' 'Form1 ' Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14) Me.ClientSize = New System.Drawing.Size(536, 581) Me.Controls.Add(Me.btnOpenBrower) Me.Controls.Add(Me.TreeView1) Me.Name = "Form1" Me.Text = "Form1" Me.ResumeLayout(False)
End Sub
#End Region Private Sub OpenBrower() Dim f As New FolderBrowserDialog If f.ShowDialog = DialogResult.OK Then Me.TreeView1.Nodes.Clear() Me.SuspendLayout() Dim nodeTemp As TreeNode = CType(Me.Invoke(New AddTreeNodeHandler(AddressOf Me.AddFileToTreeview), New Object() {f.SelectedPath}), TreeNode) |
|
出处:本站原创 作者:佚名 |
|
|