open another form in the same window , how can i do this in C# window application

Parth48
Parth48 used Ask the Experts™
on
i have created one C# window application (Inventory Software), in this application when i click on menu then form open in separate window, now i want the form in same window , but how can i do this ?
for reference i have attached .exe file of my application (which is in debug folder)
find the attachment ...
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Author

Commented:
here i have attached the .exe file ...

Inventory-Software.exe
Éric MoreauSenior .Net Consultant
Top Expert 2016

Commented:
Commented:
I would rather using a usercontrol to fullfill your task. Your will need to move all your codes from the forms to the usercontrol.

However, if you want to keep all your forms and insist on your original idea, then you can try this code:

Then I normally use a panel control on the main form to make the positioning easier.

            theForm = new Form2();
            Form1.ShowFormInControl(this.panel1, theForm);
            theForm.Show();

public static void ShowFormInControl(Control ctlContainer, Form frmEmbed) 
    { 
        frmEmbed.TopLevel = false; 
        frmEmbed.FormBorderStyle = FormBorderStyle.None; 
        frmEmbed.Dock = DockStyle.Fill; 
        frmEmbed.Visible = true; 
        ctlContainer.Controls.Add(frmEmbed); 
    }

Open in new window

OWASP: Threats Fundamentals

Learn the top ten threats that are present in modern web-application development and how to protect your business from them.

Author

Commented:
thanks its working , but menu display twice when i click on add item, what can i do ?
18-10-2010-10-12-43.jpg
Have a look at MDI-applications: use the IsMDIContainer (for the parent form) and isMDIChild (for the child form) properties.

Author

Commented:
individual panel for each form or same panel ??
means
for form 1 panel1
for form 2 adding panel2
??

Author

Commented:
can u tell me basic scenario for mdi parent and mdi child ?
For example Word and Excel are MDI applications: they have one main window (MDI container), and for each document you open, that document has its own window (MDI Child) that can be moved inside the applications main window.  The child windows can be minimized, maximized, or tiled, but they cannot be moved outside the parent window.
Multiple child windows can be opened at the same time.

For an example on how to do this in VB.NET:
http://msdn.microsoft.com/en-us/library/ms973874.aspx

Author

Commented:
but how can i do it in my application ?
the above code is working for only two forms ,
for other forms how can i do this ?

Main form is here . and i want to open all the forms in that parent form (e.g Main Form) ..
Why would that work for 2 forms?  You can create as many MDI child windows as you want, and those can be the same type (multiple product-forms, for example), or they could be totally different forms (a few product-forms, a customer-form, an invoice-form, ...).

Author

Commented:
the code written by @ trestan : is right for more than 2 forms ?
or anything changes in that code ?

Commented:
One panel is enough for all forms. You can of course put more than 2 forms in the main form. You need to remove the menu bar from the child forms.

Commented:
Is this your first C# project?

Author

Commented:
yes this is my first C# project ...

Author

Commented:
thanks @trestan : it's working now...
thanks very much ....

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial