As OriginalGriff explains to you here, you can remove a Panel, or UserControl, or other ContainerControl, from a Form's ControlCollection, and then add it to another Form (or UserControl's, etc.) ControlCollection.
It is not good programming practice, however, to put a Form itself inside another Form, or inside some other ContainerControl; the reasons why this is not a good idea get a bit esoteric, but I would use the analogy that you don't need a sledge-hammer to drive a nail into a wall made out of wood: a form in a form or panel is unnecessariliy "heavy."
Before you read the example shown here that moves a UserControl back and forth from MainForm to secondary Form, consider the idea that you can make a Panel, or UserControl, expand to fill the Form by setting its 'Dock Property to 'Fill, followed by using 'SendToBack() so it will cover other Controls on the Form. You can then reset the UserControl's 'Size and 'Position by setting the 'Dock Property back to 'None.
To use another Form shown 'Maximized to display a UserControl:
0. create the UserControl with the Controls you need, setting 'Anchor and 'Dock positions to create the UI you want. call it 'UserInterface1
0.a. do the right thing to expose the Controls on the UserControl, or to provide public Event Handlers that our Main Form can subscribe to when the user interacts with the Controls.
1. create the Form to hold the UserControl and show it occupying the full Form client area. call it 'FullScreenViewForm
1.a. set the form's 'WindowState property to 'Maximized.
1.b add this code to the full size view form:
using System.Windows.Forms;
namespace YourNameSpace
{
public partial class FullScreenViewForm : Form
{
public FullScreenViewForm()
{
InitializeComponent();
}
public UserInterface1 FullScreenViewUserControl { set; get; }
public void SetUserInterface(UserInterface1 usercontrol)
{
this.FullScreenViewUserControl = usercontrol;
this.Controls.Add(FullScreenViewUserControl);
FullScreenViewUserControl.Dock = DockStyle.Fill;
}
}
}
2. place an instance of the 'UserInterface1 Usercontrol on your Main Form, and place it where you want it: 'userInterface11
2.a. put a Button on the Main Form named: 'btnSwitchUserControlViewState
2.b. wire-up this Button's Click EventHandler as shown below
3. you'll control where the instance of 'UserInterface1 appears like this in the Main Form:
using System;
using System.ComponentModel;
using System.Windows.Forms;
namespace YourNameSpace
{
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
}
private FullScreenViewForm fullViewForm;
private bool UCViewIsLocal = true;
private void Form1_Load(object sender, EventArgs e)
{
fullViewForm = new FullScreenViewForm();
fullViewForm.Closing += FullViewFormOnClosing;
this.Closing += OnClosing;
}
private void OnClosing(object sender, CancelEventArgs cancelEventArgs)
{
if (fullViewForm != null)
{
fullViewForm.FormClosing -= FullViewFormOnClosing;
fullViewForm.Close();
}
}
private void FullViewFormOnClosing(object sender, CancelEventArgs cancelEventArgs)
{
if (fullViewForm != null && fullViewForm.FullScreenViewUserControl != null)
{
this.SuspendLayout();
fullViewForm.FullScreenViewUserControl.Dock = DockStyle.None;
fullViewForm.Controls.Remove(fullViewForm.FullScreenViewUserControl);
this.Controls.Add(fullViewForm.FullScreenViewUserControl);
this.ResumeLayout();
fullViewForm.Hide();
cancelEventArgs.Cancel = true;
UCViewIsLocal = true;
}
}
private void btnSwitchUserControlViewState_Click(object sender, EventArgs e)
{
if (UCViewIsLocal)
{
this.SuspendLayout();
fullViewForm.SetUserInterface(userInterface11);
fullViewForm.Show();
fullViewForm.BringToFront();
this.ResumeLayout();
UCViewIsLocal = false;
}
else
{
fullViewForm.Close();
}
}
}
}
Notes:
1. create the "full view form" once, and then show and hide it.
2. this code relies on the "full view form" 'Closing Event to do the right thing to return the UserControl back to its site on the Main Form, but, since the code in that EventHandler always prevents the Form from closing ...
... We could rely on the fact that for a WinForms App the Main Form being closed also close all other open Forms created by the Application ...
however ... it is better programming practice to put a FormClosing EventHandler on the Main Form and to make sure we have un-plugged the EventHandler for FormClosing from the form we are using to view the UserControl expanded to full-screen size.