Can I host a Windows Form inside a control
Solution 1:
You can turn a Form class back to a child control by setting its TopLevel property to False. It becomes essentially a UserControl with some unused overhead. Make it look similar to this:
Public Class Form1
Public Sub New()
InitializeComponent()
Dim frm As New Form2
frm.TopLevel = False
frm.FormBorderStyle = Windows.Forms.FormBorderStyle.None
frm.Visible = True
frm.Dock = DockStyle.Fill
TabPage1.Controls.Add(frm)
End Sub
End Class
Solution 2:
Any window can be hosted in any other window (a Control is a window, technically) using SetParent
.
<System.Runtime.InteropServices.DllImport("user32.dll")>
Public Function SetParent(ByVal hWndChild As IntPtr, ByVal hWndNewParent As IntPtr) As IntPtr
End Function
to declare and
SetParent(FormToHost.Handle, ControlToHostForm.Handle)
to use. It may not be ideal but it's okay if you don't want to put any more effort into this, like you say. The forms will maximize and minimize properly, and will not show up in the taskbar, and will close with their containers.