tags:

views:

507

answers:

6

I want to use a win-form in C# and display its contents or the whole form in a panel used in another form.

Lets say i have a form A with a panel Panel_of_A and a form B with a panel Panel_of_B

I want to display contents of Panel_of_A into Panel_of_B or you may say i want to use Panel_of_A in another form.

Or you may provide help for displaying a form say A into a panel on form B.

Hope i made u understand my thoughts...

+7  A: 

I think a better way for doing this is to create a User Control which contains that panel and (re)use it on both forms.

Here is a tutorial how to create User Controls on MSDN.

splattne
+1: You got in just before me, dumb slow fingers . . .
Binary Worrier
+1  A: 

I would suggest defining the panel you want to reuse as a separate class, and place this on both forms. If you need the displayed data to be the same as well, bind to a business object than can be passed between the forms.

Eyvind
+2  A: 

Create a user control that contains the logic you want to replicate, then incude the new user control in both places.

Binary Worrier
+1 for the right answer and your comment on my answer. ;-)
splattne
+1  A: 

How's this for displaying an instance of FormA inside a panel on FormB? The UserControl is probably the better way to go, but what you asked for is possible.

fa = new FormA();
fa.TopLevel = false;
fa.FormBorderStyle = FormBorderStyle.None;
fa.Dock = DockStyle.Fill; 

fb = new FormB();
fb.panel1.Controls.Add(fa); // if panel1 was public

fa.Show();
fb.Show();
frou
This one didn't work man:$ I tried it.
Mobin
What was the problem? I threw together a quick test when I posted the answer and it did work for me.
frou
A: 

Depending on the size and scale of your application, you may want to consider the (free) Composite UI Application Block

From the blurb:

It provides proven practices to build complex smart client user interfaces based on well known design patterns such as the Composite pattern, in which simple user interface parts can be combined to create complex solutions, but at the same time allowing these parts to be independently developed, tested, and deployed.

Winston Smith