Video summary
C Sharp Multiple Forms in One Panel
Main summary
Key takeaways
Summary
The presenter demonstrates how to display different Windows Forms inside a single panel in a C# application. The example uses Form1 as the main form, with a panel and buttons that load Form2, Form3, or Form4 into that panel.
Method 1: Write the code in each button handler
For each button’s click event:
- Clear the panel with
panel1.Controls.Clear()to remove the previously displayed form. - Create an instance of the form to display, such as
new Form2(). - Set the form’s
TopLevelproperty tofalse, allowing it to be hosted inside another control. - Add the form to the panel’s controls.
- Call
Show()to display it.
The presenter repeats this pattern for Forms 3 and 4, changing the form instance for each button.
Method 2: Use a reusable helper function
To avoid repeating the same code in every button handler, create a function that accepts a Form parameter. Inside the function:
- Clear the panel.
- Add the supplied form to the panel.
- Set its
TopLevelproperty tofalse. - Show it.
Each button’s click handler can then call the helper and pass a new instance of the desired form, such as new Form2().
This approach keeps the button handlers shorter and centralizes the form-loading logic.
Key takeaway
Multiple forms can be displayed in the same panel by clearing the panel, configuring each form as a non-top-level form, adding it to the panel, and showing it.
Speakers and sources
- Presenter/narrator: One speaker gives the tutorial; the subtitles do not state their name. The video is associated with the Jorge Resurreccion channel.
- Other source mentioned: The presenter refers viewers to a separate Visual Basic tutorial on displaying multiple forms in one panel.
Rate this summary
Your feedback will help improve summaries.
Improve this summary
Reprocess with a stronger model when the summary feels incomplete or inaccurate.
Translate summary in another language
Ask questions to this video
Chat for follow-up questions, clarifications, and source-backed answers.