0

我正在获取文件夹名称,并在同一目录中获取 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

两者都在同一个列表框中混合和排序1 然后我添加 axacropdf(PDF 组件)来阅读 pdf 文件。如何从列表框中的选定项目打开/获取路径以在 axacropdf 中打开?

(axacropdf.src =)
4

1 回答 1

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
于 2018-02-04T03:36:05.333 回答