tags:

views:

61

answers:

3

lets say i have a main form which have a lot of functionallity.
this form have a tab control in which each tab contain some set of functionality.
what i want to do is when i click on each tab controls button i want to load a form into the client area of the tab control.
so instead of having a lot of controls in the main form , i will only have set of forms and each form will have its control.
i think this is will be better in term of managing the controls so i dont have like 150 control on the main form. so basically i want to load a form on another form and not show the form in a seperate view.
if its not possible with forms then can i use another control that will group the controls and will be loaded on the main form?
thanks

+2  A: 

Alternate 1 :

You can make each of the form as a User Control and then you can load the appropriate user control in a blank panel in your main form whenever required.

You should be able to find a way to communicate between your form and those user controls.

Alternate 2 :

You can show the appropriate Form using ShowModal() method, with the main form as parent, that way user can finish the work with the child form, before coming back to the main form.

Disadvantages here are user wont be able to interact with the main form as long as the child form is closed.

The King
+1  A: 

I would recommend looking into User Controls.

User Controls come with a designer, just like forms, and have a rich event model to tap into. Unlike forms, they are easy to embed into other controls and forms. As a matter of fact, user controls will show up in your toolbox to drag-and-drop onto another form.

It's at least worth taking a look at.

kbrimington
thanks , but after i created the user control how do i put it in the main form? i dont see the user control in the toolbox. and i have read the article and didnt see anything about that there.
Karim
@Karim - http://stackoverflow.com/questions/3628163/c-custom-control-doesnt-show-up-in-the-toolbox/3628310#3628310 helps you solve your problem
devnull
+1  A: 

Following code adds one Form to a panel in another form.

Add this code in Form1

        Form2 ff = new Form2();
        ff.TopLevel = false;

        ff.Dock = DockStyle.Fill;
        ff.ControlBox = false;
        ff.Text = "";

        panel1.Controls.Add(ff);
        ff.Show();

The flip side is your panel should be big enough to accomodate the form...

The King
intersting idea really. i will check if it works and if it works i will set it as accepted answer. really nice code though :) this have the plus that i dont need to change the old code into user controls and also i can use the form as a form sometimes with ,show() and sometimes as a user control.
Karim