在c#.Net中打开Form as Tab [英] Open Form as Tab in c#.Net

查看:96
本文介绍了在c#.Net中打开Form as Tab的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hi
我想在c#中使用 devcomponent tabControl打开子项

喜欢这个代码

  //  表单的TopLevel设置为false  
childForm.TopLevel = false ;
// 添加了新的TabPage
TabPage tbp = new TabPage();
tabControl1.TabPages.Add(tbp);
tbp.Controls.Add(childForm);
// 在表格中添加表格
childForm.WindowState = FormWindowState.Maximized;
childForm.Show();



谢谢

解决方案

请参阅我对答案的评论;不要这样做。由于一个非常好的理由,表格( TopLevel 默认为true)的子父关系已失效。而不是子窗体,使用一些其他容器控件,如 Panel TabPage 本身。



如果您尝试的唯一原因是您想使用设计器,请创建一个用户控件而不是该子窗体。



-SA


首先:从您提出的问题 我们无法判断您是否可以使用你在DevComponent的TabControl中显示的代码示例没有错误...现在。



第二:我同意你应该在DevComponent论坛上提出这个问题的评论。 />


第三:我同意谢尔盖,你应该几乎总是永远不会让表格成为另一个表格的孩子。虽然我不同意谢尔盖认为这是已经不复存在......因为你仍然可以做到这一点......我强烈赞同他使用旧的MDI架构,其中使用Forms作为ChildForms标准程序已经过时了,而且如果可能的话,应该避免它。



我反对使用表格作为另一个表格的孩子只是基于:




2. PLOS:最少惊喜的原则:这是一种非标准的技术,你将来可能会遇到维护或延期的麻烦。



现在,毕竟:如果您这样做,我建议:



1.在每张表格上放置一个您可能希望出现在将来作为TabPage的内容。将Panel的'Dock属性设置为'Fill。



2.将所有控件放在面板上(菜单,工具提示等除外) 。



3.将公共财产放在表格上公开小组。



4.如果当你想让Panel显示为TabPages的内容时:



TabPage1.Controls.Add(SomeForm1.TheFutureTabPanel);

SomeForm1。隐藏();

hi I want to open child from as tab in c# with devcomponent tabControl
like this code

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

解决方案

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


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


这篇关于在c#.Net中打开Form as Tab的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆