Click here to Skip to main content
15,906,567 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
hi I want to open child from as tab in c# with devcomponent tabControl
like this code
C#
//TopLevel for form is set to false
 childForm.TopLevel = false;
 //Added new TabPage
 TabPage tbp =new TabPage();
 tabControl1.TabPages.Add(tbp);
 tbp.Controls.Add(childForm);
 //Added form to tabpage
 childForm.WindowState = FormWindowState.Maximized;
 childForm.Show();

thank you
Posted
Comments
ZurdoDev 27-Jan-15 10:31am    
What's the problem?
Suvendu Shekhar Giri 27-Jan-15 13:18pm    
Why don't you ask them for support? Are they denying?
Ask the same question here
http://www.devcomponents.com/support.aspx
Sergey Alexandrovich Kryukov 27-Jan-15 14:41pm    
Don't do this super-puper abuse. Why?
—SA

Please see my comment to the answer; don't do it. Child-parent relationship is made defunct for forms (TopLevel is true by default) for a really good reason. Instead of the child forms, use some other container controls, such as Panel or TabPage itself.

If the only reason for what you are trying is that you would like to use the designer, create a user control instead of that child form.

—SA
 
Share this answer
 
v2
First: From your question as asked we can't tell if you can use the code example you show in DevComponent's TabControl without error ... now.

Second: I agree with the comment that you should be asking this on the DevComponent Forum.

Third: I agree with Sergey that you should almost always never make a Form a child of another Form. While I do not agree with Sergey that this is "made defunct" ... because you can still do it ... I agree with him strongly that using the old MDI architecture where using Forms as ChildForms was standard procedure is outmoded, and one should avoid it, if possible.

My objection to using a Form as a Child of another Form is simply based on:

1. parsimony: Forms are "heavy-weight" objects with lots of functionality one doesn't normally need for a component inside another Form. If you can use a lighter-weight object for the same result, without complication ... and you can ... why not use the lighter-weight object ?

2. PLOS: principle of least surprise: it's such a non-standard technique that you may have trouble in the future with maintenance or extension.

Now, after all that: if you have to do this, I suggest:

1. put a Panel on each Form that you may wish to appear in the future as the contents of a TabPage. Set the Panel's 'Dock property to 'Fill.

2. place all your Controls on that Form (except, perhaps, Menus, ToolTips, etc.) in the Panel.

3. put a public property on the Form that exposes the Panel.

4. if and when you want that Panel to appear as a TabPages's content:

TabPage1.Controls.Add(SomeForm1.TheFutureTabPanel);
SomeForm1.Hide();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900