我需要编写一个代码来在面板元素中运行记事本,我已经将它写在主窗体中但是我找不到将其写入面板的解决方案,这是我的代码:
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
答案 0 :(得分:0)
只需将Me.Handle
替换为Panel1.Handle
(或您的小组名称):
SetParent(Process1.MainWindowHandle, Panel1.Handle)
SetParent
的第二个参数指定您希望外部进程成为子进程的窗口(=控件)的窗口句柄(hWnd)。
在WinForms中,从System.Windows.Forms.Control
继承的所有控件都通过JVM公开其窗口句柄。