Ask Your Question
3

How can a form window be created within an already existing window in C# without the need for additional tools or frameworks?

asked 2021-10-07 11:00:00 +0000

lalupa gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2022-04-05 01:00:00 +0000

ladyg gravatar image

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();
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2021-10-07 11:00:00 +0000

Seen: 10 times

Last updated: Apr 05 '22