在Panel下运行外部应用程序

时间:2018-03-16 21:21:22

标签: vb.net

我需要编写一个代码来在面板元素中运行记事本,我已经将它写在主窗体中但是我找不到将其写入面板的解决方案,这是我的代码:

Imports System.Diagnostics
Imports System.Runtime.InteropServices
Public Class Form1
    <DllImport("user32.dll")> Public Shared Function SetParent(ByVal hwndChild As IntPtr, ByVal hwndNewParent As IntPtr) As Integer


End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    Process1.StartInfo.FileName = ("notepad.exe")
    Process1.Start()

    Do Until Process1.WaitForInputIdle = True
        'Nothing
    Loop
    SetParent(Process1.MainWindowHandle, Me.Handle)
End Sub

1 个答案:

答案 0 :(得分:0)

只需将Me.Handle替换为Panel1.Handle(或您的小组名称):

SetParent(Process1.MainWindowHandle, Panel1.Handle)

SetParent的第二个参数指定您希望外部进程成为子进程的窗口(=控件)的窗口句柄(hWnd)。

在WinForms中,从System.Windows.Forms.Control继承的所有控件都通过JVM公开其窗口句柄。

相关问题