我正在获取文件夹名称,并将pdf文件放在同一目录中,并使用以下代码列在同一个列表框中:
Private Sub frmBooks_Load(sender As Object, e As EventArgs) Handles MyBase.Load
For Each folder As String In System.IO.Directory.GetDirectories(Application.StartupPath & "\Books")
ListBox1.Items.Add(Path.GetFileName(folder))
Next
For Each file As String In System.IO.Directory.GetFiles(Application.StartupPath & "\Books\", "*.pdf")
ListBox1.Items.Add(Path.GetFileNameWithoutExtension(file))
Next
在同一个listbox1中混合和分类 然后我添加axacropdf(PDF组件)来读取pdf文件。 如何打开/获取列表框中选定项目的路径,以便在axacropdf中打开?
(axacropdf.src =)
答案 0 :(得分:0)
此代码检查文件是否以.pdf
存在Private Sub ListBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListBox1.SelectedIndexChanged
If File.Exists(Application.StartupPath & "\Books\" & ListBox1.SelectedItem.ToString & ".pdf") = True Then
AxAcroPDF1.src = (Application.StartupPath & "\Books\" & ListBox1.SelectedItem.ToString & ".pdf")
end if
end sub