Technology Experience

Contenuti gestiti da Igor Damiani
posts - 949, comments - 2741, trackbacks - 15120

My Links

News

  • Questo blog si propone di raccogliere riflessioni, teoriche e pratiche, su tutto quello che riguarda il world-computing che mi sta attorno: programmazione in .NET, software attuale e futuro, notizie provenienti dal web, tecnologia in generale, open-source.

    L'idea è quella di lasciare una sorta di patrimonio personale, una raccolta di idee che un giorno potrebbe farmi sorridere, al pensiero di dov'ero e cosa stavo facendo.

    10/05/2005,
    Milano

Archives

Post Categories

Generale

Codice per testare timer, thread, listview e treeview

Imports System.IO
Imports Microsoft.Win32

'http://www.devx.com/vb2themax/Tip/19228

Public Class Form3
    Inherits System.Windows.Forms.Form

    Private ElencoFiles() As String
    Private TipiFiles As ArrayList

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    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

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer. 
    'Do not modify it using the code editor.
    Friend WithEvents lstElenco As System.Windows.Forms.ListView
    Friend WithEvents clmNomeFile As System.Windows.Forms.ColumnHeader
    Friend WithEvents clmDim As System.Windows.Forms.ColumnHeader
    Friend WithEvents clmTipoFile As System.Windows.Forms.ColumnHeader
    Friend WithEvents trvElenco As System.Windows.Forms.TreeView
    Friend WithEvents Button1 As System.Windows.Forms.Button
    Friend WithEvents Timer1 As System.Windows.Forms.Timer
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container
        Me.lstElenco = New System.Windows.Forms.ListView
        Me.clmNomeFile = New System.Windows.Forms.ColumnHeader
        Me.clmDim = New System.Windows.Forms.ColumnHeader
        Me.clmTipoFile = New System.Windows.Forms.ColumnHeader
        Me.trvElenco = New System.Windows.Forms.TreeView
        Me.Button1 = New System.Windows.Forms.Button
        Me.Timer1 = New System.Windows.Forms.Timer(Me.components)
        Me.SuspendLayout()
        '
        'lstElenco
        '
        Me.lstElenco.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
                    Or System.Windows.Forms.AnchorStyles.Left) _
                    Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.lstElenco.Columns.AddRange(New System.Windows.Forms.ColumnHeader() {Me.clmNomeFile, Me.clmDim, Me.clmTipoFile})
        Me.lstElenco.FullRowSelect = True
        Me.lstElenco.Location = New System.Drawing.Point(8, 8)
        Me.lstElenco.Name = "lstElenco"
        Me.lstElenco.Size = New System.Drawing.Size(496, 136)
        Me.lstElenco.TabIndex = 0
        Me.lstElenco.View = System.Windows.Forms.View.Details
        '
        'clmNomeFile
        '
        Me.clmNomeFile.Text = "Nome File"
        Me.clmNomeFile.Width = 161
        '
        'clmDim
        '
        Me.clmDim.Text = "Dimensione"
        Me.clmDim.Width = 154
        '
        'clmTipoFile
        '
        Me.clmTipoFile.Text = "Tipo File"
        Me.clmTipoFile.Width = 177
        '
        'trvElenco
        '
        Me.trvElenco.ImageIndex = -1
        Me.trvElenco.Location = New System.Drawing.Point(8, 152)
        Me.trvElenco.Name = "trvElenco"
        Me.trvElenco.SelectedImageIndex = -1
        Me.trvElenco.Size = New System.Drawing.Size(240, 168)
        Me.trvElenco.TabIndex = 1
        '
        'Button1
        '
        Me.Button1.Location = New System.Drawing.Point(256, 152)
        Me.Button1.Name = "Button1"
        Me.Button1.TabIndex = 2
        Me.Button1.Text = "Button1"
        '
        'Timer1
        '
        Me.Timer1.Enabled = True
        Me.Timer1.Interval = 5000
        '
        'Form3
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(512, 325)
        Me.Controls.Add(Me.Button1)
        Me.Controls.Add(Me.trvElenco)
        Me.Controls.Add(Me.lstElenco)
        Me.Name = "Form3"
        Me.Text = "Form3"
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ElencoFiles = Directory.GetFiles("D:\Deploy")

        Dim i As Integer
        Dim Riga As ListViewItem
        TipiFiles = New ArrayList
        For i = 0 To ElencoFiles.Length - 1
            Riga = Me.lstElenco.Items.Add(ElencoFiles(i))
            Riga.SubItems.Add(New FileInfo(ElencoFiles(i)).Length)
            TipiFiles.Add(GetFileDescriptionFromReg(ElencoFiles(i)))
            Riga.SubItems.Add(GetFileDescriptionFromReg(ElencoFiles(i)))
        Next

        TipiFiles = GetUniqueValues(TipiFiles)
        PopolaTreeView()
    End Sub

    Private Sub PopolaTreeView()
        Dim i As Integer
        For i = 0 To TipiFiles.Count - 1
            Me.trvElenco.Nodes.Add(TipiFiles(i))
        Next
    End Sub

    Private Function GetFileDescriptionFromReg(ByVal FileName As String) As String
        Dim classname As String
        Dim Reg As RegistryKey

        ' get the classname from the registry
        'classname = Registry.ClassesRoot.GetValue(New FileInfo(FileName).Extension)
        Reg = Registry.ClassesRoot.OpenSubKey(New FileInfo(FileName).Extension)
        If IsNothing(Reg) = False Then
            classname = Reg.GetValue("", "")
            'classname = GetRegistryValue(HKEY_CLASSES_ROOT, ext, "")
            If Len(classname) Then
                Reg = Registry.ClassesRoot.OpenSubKey(classname)
                Return (Reg.GetValue("", ""))
                'GetFileDescriptionFromReg = GetRegistryValue(HKEY_CLASSES_ROOT, _
                '    classname, "")
            End If
        Else
            Return ""
        End If
    End Function

    Private Function GetUniqueValues(ByRef Elenco As ArrayList) As ArrayList
        Dim Valore As String = "#"
        Dim i As Integer
        GetUniqueValues = New ArrayList

        'Ordino l'elenco source
        Elenco.Sort()
        For i = 0 To Elenco.Count - 1
            If Elenco(i) <> Valore Then
                GetUniqueValues.Add(Elenco(i))
                Valore = Elenco(i)

                If Valore = Elenco(Elenco.Count - 1) Then Exit For
            End If
        Next

        Return (GetUniqueValues)
    End Function

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Me.lstElenco.Items.Clear()
        Me.trvElenco.Nodes.Clear()
        Form3_Load(Nothing, Nothing)
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Me.lstElenco.Items.Clear()
        Me.trvElenco.Nodes.Clear()
        Form3_Load(Nothing, Nothing)
    End Sub
End Class

Print | posted on lunedì 18 aprile 2005 16:09 |

Feedback

Gravatar

# Windows Forms : Timer, ListView e TreeView

Comments have been closed on this topic.

Powered by:
Powered By Subtext Powered By ASP.NET