簡體   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