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
但這個詞應用仍然是我的計劃之外,而不是在面板中打開!
任何想法?並感謝您的期待!