Mothy
Mothy

Reputation: 416

Open a form within the parent form-Not as separate screen in c#

I have a parent form with a button and when in the click event of the button I want to open a new form.

Form2 form2= new Form2();
form2.Show();

But, form2 is opened as a separate process. I want the form to opened inside the parent form.

While googled I found out that MDI is being deprecated. So could you please suggest me a good way?

Upvotes: 1

Views: 1254

Answers (2)

ispiro
ispiro

Reputation: 27743

Form f = new Form();
f.TopLevel = false;
f.Visible = true;
Controls.Add(f);

enter image description here

Upvotes: 2

Hans Passant
Hans Passant

Reputation: 942438

While googled I found out that MDI is being deprecated

This is like Mark Twain's famous quote: "The reports of my death have been greatly exaggerated". MDI is built into Windows, many old programs depend on it. It has been around for over 25 years and is not going away anytime soon.

Programmers like to arbitrarily announce something deprecated when they don't like a feature. Sure, nobody is that smitten with MDI. That WPF didn't implement it doesn't make it deprecated, that would make shell notify icons deprecated too and they certainly are alive and well. MDI was a windowing model that was invented to deal with the kind of monitors users had 25 years ago. And 640 x 480 displays don't leave a lot of room for windows. Finding a way to make overlapping windows manageable was its primary goal.

It doesn't make much sense to still use it on the gigantic monitors we have today. Docking layouts are much more sensible. Visual Studio being a good example. You'll need to go shopping for a library that support it if you don't want to create one yourself. Weifenluo's DockPanelSuite is very popular and has the right price.

Upvotes: 4

Related Questions