我在一个显示Webbrowser
文件的表单中有一个pdf
控件。我必须将URL指定为计算机上的文件位置。
例如
E:\Folder\Manual.pdf
pdf
文件和程序都在同一个文件夹中。
如何指定URL,以便在将文件夹移动到另一个驱动器时,它会打开相同的pdf文件?
答案 0 :(得分:9)
您的申请的位置是
Dim path as String = My.Application.Info.DirectoryPath
你可以使用:
Dim pdffile as String = IO.Path.Combine(path, "pdffile.pdf")
WebBrowser1.Navigate(pdffile)
答案 1 :(得分:2)
如果我理解正确,那么:
Dim myPdf As String =
IO.Path.Combine(IO.Directory.GetParent(Application.ExecutablePath).FullName, "myPdfFile.pdf")
答案 2 :(得分:0)
你能做到的另一种方法是使用类似下面代码的东西;
Private Sub FamilyLocateFile_Click(sender As Object, e As EventArgs) Handles FamilyLocateFile.Click
If LocateFamilyDialog.ShowDialog = DialogResult.OK Then
FamilyWMP.URL = LocateFamilyDialog.FileName
ElseIf LocateFamilyDialog.ShowDialog = DialogResult.Cancel Then
MsgBox(MsgBoxStyle.Critical, "Error!")
End If
End Sub
这样做是在Windows Media Player ActiveX对象中播放文件。可以使用OpenFile对话框选择该文件,在本例中称为LocateFamilyDialog。您不需要语句的ElseIf部分,但您需要插入一个打开的文件对话框和一个可以显示PDF的控件。我认为它可以与WebBrowsers合作,但我不确定。