1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
| Public Class AppHostForm
Inherits Form
Private _hostPanel As Panel
Public Sub New()
_hostPanel = New Panel()
_hostPanel.Size = New Size(ClientSize.Width - 50, ClientSize.Height - 50)
_hostPanel.Location = New Point(25, 25)
_hostPanel.BackColor = Color.Black
_hostPanel.Anchor = AnchorStyles.Bottom Or AnchorStyles.Right Or AnchorStyles.Left Or AnchorStyles.Top
Me.Controls.Add(_hostPanel)
Dim btn As New Button()
btn.Text = "Run app"
AddHandler btn.Click, AddressOf btn_Click
Me.Controls.Add(btn)
End Sub
Private Sub btn_Click(sender As Object, e As EventArgs)
Dim dialog = New OpenFileDialog()
dialog.Filter = "Exécutable|*.exe"
If dialog.ShowDialog() = DialogResult.OK Then
Dim proc = Process.Start(dialog.FileName)
proc.WaitForInputIdle()
If proc.MainWindowHandle <> IntPtr.Zero Then
SetParent(proc.MainWindowHandle, _hostPanel.Handle)
End If
End If
End Sub
<DllImport("user32")> _
Private Shared Function SetParent(child As IntPtr, newParent As IntPtr) As IntPtr
End Function
End Class |