2013-04-29 89 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