Hey Toby,
I had the same question when I started using C# after using Delphi since
1995. I used TFrames all the time to switch in and out different views of my
applications. It was very convenient. I was actually suprised when I did
not find an equivalent in .NET. I found the best way to have something
equivalent to a TFrame was to create a new form. This form can be
programmatically added into another form.
Here's a little walkthrough:
- Create a new WinForms project (I use C#).
- Add a panel to the form, sizing it large enough to host the other form.
- Add a button to the form.
- Add a second form to the project. This will be our TFrame.
- Add whatever controls you want on the TFrame form.
- Set the FormBorderStyle of the TFrame form to None.
- Add the following code to the click event of the form on the first form:
Form2 form = new Form2();
form.TopLevel = false;
form.Parent = pnlDock;
form.Show();
This is all you have to do. If you want to keep a reference to the form,
create a private variable at the first form level to be able to close out the
TFrame form. You could also do as in Delphi and set up a base form with all
of the common events and properties created and inherit your TFrame forms
from it. Then you can use the common private variable to reference any of
the inherited form's data.
You can set other properties such as docking and anchoring in the panel to
spruce up the exact position of the form in the panel. If the form is larger
than the panel, you can set the AutoScroll property of the panel to
automatically add scrollbars to the size of the TFrame form.
I hope this helps. If you have any questions, let me know.
Shannon