积极答复者
【继承】继承tabcontrol后,如果拖动一个新的控件,初始不让他产生2个tabpage,如何做到

问题
答案
-
这是Visual Studio.Net本身具有的设计。 而不是您自定义开发控件的结果!
请看下面的一片博文,专门讨论了这个问题:
如何去掉TabControl控件默认添加的TabPage:
http://www.cnblogs.com/xuefeng1982/archive/2010/08/23/1806774.html感谢您的参与!
Neddy Ren [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
-
谢谢。我实现了。。
但是,,默认的tabpage1,tabpge2在form1.designer.cs里面,不会自动删除。。
会产生载来越多没用的tabpage
带着责任感生活,尝试为这个世界带来点有意义的事情,为更高尚的事情做点贡献,这样你会发现生活更加有意义,生命不再枯燥,需要我们去做的事情很多。
这样的情况,更严格地说,是在Visual Studio中产生的。Visual Studio IDE会辅助产生2个Tabpage。但是,如果您在RunTime的时候动态添加一个空的Tabcontrol, 就不会产生任何TabPage。不妨试下下面的2段代码,你就知道了:1. 在一个空的form中,执行下面的代码:
TabControl tc = new TabControl(); tc.Dock = DockStyle.Fill; this.Controls.Add(tc);
2.同样在一个空的form中执行下面的代码:
TabControl tc = new TabControl(); tc.Dock = DockStyle.Fill; TabPage tp = new TabPage(); tp.Text = "新TabPage"; tc.TabPages.Add(tp); this.Controls.Add(tc);
对比2段代码就知道了!
Neddy Ren [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- 已标记为答案 tssing 2011年6月13日 15:07
-
[System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name = "FullTrust")]
public class ColorLabelDesigner :
System.Windows.Forms.Design.ControlDesigner
{
private DesignerActionListCollection actionLists;// Use pull model to populate smart tag menu.
public override DesignerActionListCollection ActionLists
{
get
{
if (null == actionLists)
{
actionLists = new DesignerActionListCollection();
tabcontrol tc = this.Control as tabcontrol ;
tabpage tp = new tabpage();
og.Name = "og1";
og.Text = "og1";
os.Controls.Add(og);
//actionLists.Add(
// new ColorLabelActionList(this.Component));
}
return actionLists;
}
}
}重写designer,既然成功掉了。。。
带着责任感生活,尝试为这个世界带来点有意义的事情,为更高尚的事情做点贡献,这样你会发现生活更加有意义,生命不再枯燥,需要我们去做的事情很多。- 已标记为答案 tssing 2011年6月14日 16:15
全部回复
-
这是Visual Studio.Net本身具有的设计。 而不是您自定义开发控件的结果!
请看下面的一片博文,专门讨论了这个问题:
如何去掉TabControl控件默认添加的TabPage:
http://www.cnblogs.com/xuefeng1982/archive/2010/08/23/1806774.html感谢您的参与!
Neddy Ren [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
-
谢谢。我实现了。。
但是,,默认的tabpage1,tabpge2在form1.designer.cs里面,不会自动删除。。
会产生载来越多没用的tabpage
带着责任感生活,尝试为这个世界带来点有意义的事情,为更高尚的事情做点贡献,这样你会发现生活更加有意义,生命不再枯燥,需要我们去做的事情很多。
这样的情况,更严格地说,是在Visual Studio中产生的。Visual Studio IDE会辅助产生2个Tabpage。但是,如果您在RunTime的时候动态添加一个空的Tabcontrol, 就不会产生任何TabPage。不妨试下下面的2段代码,你就知道了:1. 在一个空的form中,执行下面的代码:
TabControl tc = new TabControl(); tc.Dock = DockStyle.Fill; this.Controls.Add(tc);
2.同样在一个空的form中执行下面的代码:
TabControl tc = new TabControl(); tc.Dock = DockStyle.Fill; TabPage tp = new TabPage(); tp.Text = "新TabPage"; tc.TabPages.Add(tp); this.Controls.Add(tc);
对比2段代码就知道了!
Neddy Ren [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- 已标记为答案 tssing 2011年6月13日 15:07
-
我非常好奇的想知道,为什么我点选 控件,点击移除,他会自动移除,并删除相应的代码,
而我写程序缺不行。。。
Controls.Clear();
tabpages.clear();也不行。。。。我太想知道微软是怎么做到的
带着责任感生活,尝试为这个世界带来点有意义的事情,为更高尚的事情做点贡献,这样你会发现生活更加有意义,生命不再枯燥,需要我们去做的事情很多。
正常情况下,您这样的代码是完全可以执行去除form中的控件和去除Tabcontrol中的控件,不妨上传下您的代码给我们,让我们为您分析下!您可以将您的代码打包并上传到MSN中的SkyDrive的公开文件夹中,并将连接提供给我们!
Neddy Ren [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
-
[System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name = "FullTrust")]
public class ColorLabelDesigner :
System.Windows.Forms.Design.ControlDesigner
{
private DesignerActionListCollection actionLists;// Use pull model to populate smart tag menu.
public override DesignerActionListCollection ActionLists
{
get
{
if (null == actionLists)
{
actionLists = new DesignerActionListCollection();
tabcontrol tc = this.Control as tabcontrol ;
tabpage tp = new tabpage();
og.Name = "og1";
og.Text = "og1";
os.Controls.Add(og);
//actionLists.Add(
// new ColorLabelActionList(this.Component));
}
return actionLists;
}
}
}重写designer,既然成功掉了。。。
带着责任感生活,尝试为这个世界带来点有意义的事情,为更高尚的事情做点贡献,这样你会发现生活更加有意义,生命不再枯燥,需要我们去做的事情很多。- 已标记为答案 tssing 2011年6月14日 16:15