[英]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
結束班
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.