繁体   English   中英

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

[英]How to open multiple documents using vb.net file explorer?

我按照我想要的方式使用vb.net创建了一个文件浏览器,但问题是我有几个测试文件夹,每天我会在这些文件夹中放入几个pdf文件和图像,当我输入文件夹test1时,我有pdf文件newtest和我有其他文件,当我去点击一个文件时,只有当我把pdf文件的路径设置为newtest时才会打开这个文件,当我点击另一个文件时,如果我放置预设但是我会去打开另一个文件超过一千个图像文件和这些文件夹中的一千多个pdf文件,我想知道当我点击它打开的文件时我的代码是什么,当我点击另一个文件时,另一个文件打开。 我只能对每个预先选择的文件执行此操作,这是不可行的。

如代码所示:

其他

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

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

请帮帮我吗?

图像与文件浏览器设计

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

结束班

如果你仍然想点击listview项目打开它试试这个:

process.start(path & ListView1.SelectedItems(0).Text)

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

更新:

看,它对我有用,双击“internet tester.exe”打开它。 如果您的“路径”末尾不包含“\\”,请务必自行添加。 如果它对您有效,请将答案标记为答案

在此输入图像描述 在此输入图像描述 在此输入图像描述

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM