Mobin
Mobin

Reputation: 4920

Can we use a panel of some winform from another winform in C#?

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...

Upvotes: 7

Views: 3913

Answers (5)

Winston Smith
Winston Smith

Reputation: 21882

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.

Upvotes: 0

xyz
xyz

Reputation: 27837

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();

Upvotes: 2

Binary Worrier
Binary Worrier

Reputation: 51711

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

Upvotes: 4

Eyvind
Eyvind

Reputation: 5261

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.

Upvotes: 1

splattne
splattne

Reputation: 104040

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.

Upvotes: 12

Related Questions