2013-04-29 92 views
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 

但這個詞應用仍然是我的計劃之外,而不是在面板中打開!

任何想法?並感謝您的期待!

回答

1

您是否嘗試添加一個代碼後面的按鈕來啓動該過程?

「這是我怎麼會啓動這一進程

這將是你的代碼,開始控制(插入)

Dim dep1 As (INSERT YOUR EVENT HERE)= New (INSERT YOUR EVENT HERE) 
AddHandler dep.OnChange, AddressOf dep_onchange 

的實際工作按鈕

Private Sub dep_onchange1(ByVal sender As System.Object, ByVal e As System.EventArgs) 
    ' this event is run asynchronously so you will need to invoke to run on the UI thread(if required) 
    If Me.InvokeRequired Then 
     lbnoes.BeginInvoke(New MethodInvoker(AddressOf GetNoes)) 
    Else 
     GetNoes() 
    End If 
End Sub