1
我有列表框中显示的文件列表。 当我从列表框中选择一个文件时,我想要将文件加载到我的表单中的面板上。 即它的一个单词文档词将在面板中打开,如果它的PDF阅读器将打开到面板中。添加外部进程到面板vb.net
我可以得到这些文件使用
Dim ProcStart As New ProcessStartInfo
ProcStart.FileName = ListBox1.SelectedItem
Process.Start(ProcStart)
但是我不确定如何得到它,然后在我的面板停靠加载外部。我试过
Me.Panel1.Controls.Add(ProcStart)
但是这显然是错误的,因为我无法将进程添加为控件。
我做了一点googleing的,并尝试做这种方式
<DllImport("user32.dll")>
Shared Function SetParent(ByVal hWndChild As IntPtr, ByVal hWndNewParent As IntPtr) As UInteger
End Function
Private Sub ListBox1_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
Dim proc As Process
Dim AppPath As String
AppPath = lstDocs & ListBox1.SelectedItem
proc = Process.Start(AppPath)
proc.WaitForInputIdle()
SetParent(proc.MainWindowHandle, Me.Panel1.Handle)
End Sub
但这个词应用仍然是我的计划之外,而不是在面板中打开!
任何想法?并感谢您的期待!