如何使用vb.net文件浏览器打开多个文档?

时间:2019-05-24 06:05:25

标签: vb.net

我用vb.net制作了一个文件浏览器,但问题是我有几个测试文件夹,每天我都会在这些文件夹中放几个pdf文件和图像,当我进入文件夹test1时,我有pdf文件newtest,我还有其他文件,当我单击某个文件时,只有当我放置pdf文件newtest预设的路径时,它才会打开该文件;当我单击另一个文件时,如果我放置预设,则它将打开另一个文件,但是我去了这些文件夹中的一千多个图像文件和一千多个pdf文件,我想知道当我单击打开的文件时以及单击另一个文件时打开的代码。 我只能对每个预选文件执行此操作,这是不可行的。

如代码所示:

否则

Process.Start(“ C:\ Test \ test1 \ newtest.pdf”) 如果结束

我希望当我一个个地单击每个文件时打开多个文件,而不必分别为每个图像和pdf文件名编写此代码。

请帮助我吗?

Image with file explorer design

Public Class Form1
Dim path As String
Dim nextPath As String
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    On Error Resume Next
    path = TextBox1.Text
    If (My.Computer.FileSystem.DirectoryExists(path)) Then

        explorer.Clear()

        For Each i In My.Computer.FileSystem.GetDirectories(path)
            explorer.Items.Add(i.Substring(i.LastIndexOf("\") + 1), ImageList1.Images.Count() - 2)

        Next
        For Each i In My.Computer.FileSystem.GetFiles(path)
            explorer.Items.Add(i.Substring(i.LastIndexOf("\") + 1), ImageList1.Images.Count() - 1)
        Next
    Else
        MsgBox("Its A File")
        'or user
        'pocess.Start(path) // to open the file
    End If

End Sub

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    On Error Resume Next
    path = "C:\Test"
    For Each i In My.Computer.FileSystem.GetDirectories(path)
        explorer.Items.Add(i.Substring(i.LastIndexOf("\") + 1), ImageList1.Images.Count() - 2)

    Next
    For Each i In My.Computer.FileSystem.GetFiles(path)
        explorer.Items.Add(i.Substring(i.LastIndexOf("\") + 1), ImageList1.Images.Count() - 1)
    Next

End Sub

Private Sub ListView1_ItemSelectionChanged(sender As Object, e As ListViewItemSelectionChangedEventArgs) Handles explorer.ItemSelectionChanged
    nextPath = path + "\" + e.Item.Text

End Sub

Private Sub ListView1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles explorer.SelectedIndexChanged


End Sub

Private Sub ListView1_MouseDoubleClick(sender As Object, e As MouseEventArgs) Handles explorer.MouseDoubleClick
    On Error Resume Next
    If (My.Computer.FileSystem.DirectoryExists(nextPath)) Then
        path = nextPath
        explorer.Clear()
        TextBox1.Text = path
        For Each i In My.Computer.FileSystem.GetDirectories(path)
            explorer.Items.Add(i.Substring(i.LastIndexOf("\") + 1), ImageList1.Images.Count() - 2)

        Next
        For Each i In My.Computer.FileSystem.GetFiles(path)
            explorer.Items.Add(i.Substring(i.LastIndexOf("\") + 1), ImageList1.Images.Count() - 1)
        Next
    Else

        Process.Start("C:\Test\test1\newtest.pdf")
    End If

End Sub


Private Sub BtnBack_Click(sender As Object, e As EventArgs) Handles btnBack.Click

End Sub

Private Sub BtnForward_Click(sender As Object, e As EventArgs) Handles btnForward.Click

End Sub

结束班级

1 个答案:

答案 0 :(得分:0)

如果您仍然想单击列表视图项以将其打开,请尝试以下操作:

offset

这将打开C:\ test \ test1 \ newtest.pdf(例如)

更新:

看,它对我有用,双击“ internet tester.exe”将其打开。 如果您的“路径”末尾不包含“ \”,请确保自己添加。 如果您也可以将答案标记为答案

enter image description here enter image description here enter image description here