Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To create a form window within an already existing window in C# without any additional tools or frameworks, follow these steps:

  1. Create a new Windows Form Application project in Visual Studio.
  2. Add a new form to the project by right-clicking the project in the Solution Explorer and selecting Add > Windows Form.
  3. Set the form's properties as desired, such as its Size and BackgroundColor.
  4. In the main form's code, create an instance of the new form using the new keyword.
  5. Set the new form's TopLevel property to false.
  6. Add the new form to the main form's Controls collection using the Add method.
  7. Position and size the new form as desired using its Location and Size properties.

Here is an example code snippet:

// Create a new instance of the form to be added
Form subForm = new Form();
// Set the form's properties
subForm.Size = new Size(200, 200);
subForm.BackColor = Color.LightGray;
// Set the TopLevel property to false
subForm.TopLevel = false;
// Add the new form to the main form's Controls collection
this.Controls.Add(subForm);
// Position and size the new form within the main form
subForm.Location = new Point(50, 50);
subForm.Size = new Size(200, 200);
// Show the new form
subForm.Show();