Public Class frmWinGView
    Inherits System.Windows.Forms.Form

#Region " Windows フォーム デザイナで生成されたコード "

    Public Sub New()
        MyBase.New()

        ' この呼び出しは Windows フォーム デザイナで必要です。
        InitializeComponent()

        ' InitializeComponent() 呼び出しの後に初期化を追加します。

    End Sub

    ' Form は、コンポーネント一覧に後処理を実行するために 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 sbrMessage As System.Windows.Forms.StatusBar
    Friend WithEvents tvwFolder As System.Windows.Forms.TreeView
    Friend WithEvents splV As System.Windows.Forms.Splitter
    Friend WithEvents lvwGView As System.Windows.Forms.ListView
    Friend WithEvents splH As System.Windows.Forms.Splitter
    Friend WithEvents picGView As System.Windows.Forms.PictureBox
    Friend WithEvents mnuWinGView As System.Windows.Forms.MainMenu
    Friend WithEvents mnuFl As System.Windows.Forms.MenuItem
    Friend WithEvents mnuFlClose As System.Windows.Forms.MenuItem
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.sbrMessage = New System.Windows.Forms.StatusBar
        Me.tvwFolder = New System.Windows.Forms.TreeView
        Me.splV = New System.Windows.Forms.Splitter
        Me.lvwGView = New System.Windows.Forms.ListView
        Me.splH = New System.Windows.Forms.Splitter
        Me.picGView = New System.Windows.Forms.PictureBox
        Me.mnuWinGView = New System.Windows.Forms.MainMenu
        Me.mnuFl = New System.Windows.Forms.MenuItem
        Me.mnuFlClose = New System.Windows.Forms.MenuItem
        Me.SuspendLayout()
        '
        'sbrMessage
        '
        Me.sbrMessage.Location = New System.Drawing.Point(0, 297)
        Me.sbrMessage.Name = "sbrMessage"
        Me.sbrMessage.Size = New System.Drawing.Size(464, 24)
        Me.sbrMessage.TabIndex = 4
        Me.sbrMessage.Text = "StatusBar1"
        '
        'tvwFolder
        '
        Me.tvwFolder.Dock = System.Windows.Forms.DockStyle.Left
        Me.tvwFolder.ImageIndex = -1
        Me.tvwFolder.Location = New System.Drawing.Point(0, 0)
        Me.tvwFolder.Name = "tvwFolder"
        Me.tvwFolder.SelectedImageIndex = -1
        Me.tvwFolder.Size = New System.Drawing.Size(136, 297)
        Me.tvwFolder.TabIndex = 0
        '
        'splV
        '
        Me.splV.Location = New System.Drawing.Point(136, 0)
        Me.splV.Name = "splV"
        Me.splV.Size = New System.Drawing.Size(8, 297)
        Me.splV.TabIndex = 2
        Me.splV.TabStop = False
        '
        'lvwGView
        '
        Me.lvwGView.Dock = System.Windows.Forms.DockStyle.Top
        Me.lvwGView.Location = New System.Drawing.Point(144, 0)
        Me.lvwGView.MultiSelect = False
        Me.lvwGView.Name = "lvwGView"
        Me.lvwGView.Size = New System.Drawing.Size(320, 100)
        Me.lvwGView.TabIndex = 1
        '
        'splH
        '
        Me.splH.Cursor = System.Windows.Forms.Cursors.HSplit
        Me.splH.Dock = System.Windows.Forms.DockStyle.Top
        Me.splH.Location = New System.Drawing.Point(144, 100)
        Me.splH.Name = "splH"
        Me.splH.Size = New System.Drawing.Size(320, 8)
        Me.splH.TabIndex = 3
        Me.splH.TabStop = False
        '
        'picGView
        '
        Me.picGView.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
        Me.picGView.Dock = System.Windows.Forms.DockStyle.Fill
        Me.picGView.Location = New System.Drawing.Point(144, 108)
        Me.picGView.Name = "picGView"
        Me.picGView.Size = New System.Drawing.Size(320, 189)
        Me.picGView.TabIndex = 15
        Me.picGView.TabStop = False
        '
        'mnuWinGView
        '
        Me.mnuWinGView.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.mnuFl})
        '
        'mnuFl
        '
        Me.mnuFl.Index = 0
        Me.mnuFl.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.mnuFlClose})
        Me.mnuFl.Text = "ファイル(&F)"
        '
        'mnuFlClose
        '
        Me.mnuFlClose.Index = 0
        Me.mnuFlClose.Text = "閉じる(&C)"
        '
        'frmWinGView
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 12)
        Me.ClientSize = New System.Drawing.Size(464, 321)
        Me.Controls.Add(Me.picGView)
        Me.Controls.Add(Me.splH)
        Me.Controls.Add(Me.lvwGView)
        Me.Controls.Add(Me.splV)
        Me.Controls.Add(Me.tvwFolder)
        Me.Controls.Add(Me.sbrMessage)
        Me.Menu = Me.mnuWinGView
        Me.Name = "frmWinGView"
        Me.Text = "GView [Samp1103]"
        Me.ResumeLayout(False)

    End Sub

#End Region
    Private Sub frmWinGView_Load(ByVal sender As System.Object, _
                                 ByVal e As System.EventArgs) _
                                 Handles MyBase.Load
        Dim strDrive As String
        Dim myNode As TreeNode
        Dim strDrv As String

        Try
            For Each strDrv In IO.Directory.GetLogicalDrives
                '2003では、For Each strDrv As String In ・・・・
                'のようにForループ内でのみ有効な変数宣言が可能
                strDrive = strDrv.Substring(0, strDrv.Length - 1)
                '
                myNode = New TreeNode
                myNode.Text = strDrive
                Call subSetNewNode(strDrive, myNode, False)
                Me.tvwFolder.Nodes.Add(myNode)
                myNode = Nothing
            Next
        Catch ex As Exception
            MessageBox.Show(ex.Message, _
                            Me.Text, _
                            MessageBoxButtons.OK, _
                            MessageBoxIcon.Exclamation)
        End Try
    End Sub
    Private Sub subSetNewNode(ByVal v_strPath As String, _
                              ByVal va_Node As TreeNode, _
                              ByVal vblnFolder As Boolean)
        'ツリービューのノードに子フォルダを追加
        Dim myFolders As New IO.DirectoryInfo(v_strPath & "\")
        Dim myFolder As IO.DirectoryInfo
        Dim myNode As TreeNode

        Try
            If va_Node.GetNodeCount(False) = 0 Then
                For Each myFolder In myFolders.GetDirectories
                    myNode = New TreeNode
                    myNode.Text = myFolder.Name
                    va_Node.Nodes.Add(myNode)
                    myNode = Nothing
                Next
                'ドライブ指定以外のときは、自動的に展開する
                If vblnFolder Then
                    va_Node.Expand()
                End If
            End If
        Catch ex As IO.IOException
            'ドライブのIOエラーは無視
            If vblnFolder Then
                MessageBox.Show(ex.Message, _
                                Me.Text, _
                                MessageBoxButtons.OK, _
                                MessageBoxIcon.Exclamation)
            End If
        Catch ex As UnauthorizedAccessException
            'セキュリティエラーは無視
            If vblnFolder Then
                MessageBox.Show(ex.Message, _
                                Me.Text, _
                                MessageBoxButtons.OK, _
                                MessageBoxIcon.Exclamation)
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message, _
                            Me.Text, _
                            MessageBoxButtons.OK, _
                            MessageBoxIcon.Exclamation)
        Finally
            myFolders = Nothing
        End Try
    End Sub
    Private Sub tvwFolder_AfterSelect(ByVal sender As System.Object, _
                                      ByVal e As System.Windows.Forms.TreeViewEventArgs) _
                                      Handles tvwFolder.AfterSelect
        '[+]マークがないノードはBeforeExpandイベントが発生しないので
        'ノードをセレクトされたときに子ノードを取得する
        Call subSetNewNode(e.Node.FullPath, e.Node, True)
        Me.sbrMessage.Text = e.Node.FullPath
    End Sub
End Class
