简体   繁体   English

将外部过程添加到面板vb.net

[英]add external process to panel vb.net

I have a list of files displayed in a listbox. 我有一个列表框中显示的文件列表。 when I select a file from the listbox i want the file to load into a panel on my form. 当我从列表框中选择一个文件时,我希望将该文件加载到表单的面板中。 ie if its a word document word will open in the panel, if its a pdf reader wil open into the panel. 也就是说,如果它的单词文档单词将在面板中打开,如果它的PDF阅读器将在面板中打开。

I can get the files to load externally using 我可以使用以下方式将文件加载到外部

Dim ProcStart As New ProcessStartInfo
ProcStart.FileName = ListBox1.SelectedItem
Process.Start(ProcStart)

however i am unsure of how to get it to then dock in my panel. 但是我不确定如何将其停靠在面板中。 I tried 我试过了

Me.Panel1.Controls.Add(ProcStart)

but this is obviously wrong as I can't add a process as a control. 但这显然是错误的,因为我无法将流程添加为控件。

I did a bit of googleing and have tried to do it this way 我做了一些谷歌搜索,并尝试这样做

<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

but the word application still opens outside my program and not in the panel!! 但是单词application仍然在我的程序外部而不是在面板中打开!

Any ideas? 有任何想法吗? and thanks for looking! 并感谢您的光临!

Have you tried adding a button with code behind it to start the process? 您是否尝试过在按钮后面添加代码以启动该过程?

'This is how i would start the process ``这就是我开始这一过程的方式

this would be in your code that starts the control ( inserting ) 这将在您的代码中启动控件(插入)

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

the actuall button 实际按钮

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM