VS 2010生成奇怪的代码. [英] VS 2010 Generates weird code.
问题描述
我目前正在开发自己的TabControl,并且正在努力使其对设计人员友好.
我的控件由这样的类组成:
I''m currently developing my own TabControl and I am struggling to make it designer friendly.
My control is made of a class like this:
public class GlassTabControl : UserControl
{
private GlassTabPageCollection _tabList = new GlassTabPageCollection();
// the property
[Browsable(true)]
public GlassTabPageCollection TabPages
{
get { return _tabList; }
set { _tabList = value; }
}
}
在将我的GlassTabControl添加到窗体上并通过VS2010设计器将GlassTabPage添加到我的收藏集之后,我在MyForm.Designer.cs中找到了确切的代码:
After adding my GlassTabControl on a Form and adding a GlassTabPage to my collection through VS2010 designer I found the exact code in MyForm.Designer.cs:
//
// glassTabControl1
//
this.glassTabControl1.Location = new System.Drawing.Point(12, 80);
this.glassTabControl1.Name = "glassTabControl1";
this.glassTabControl1.Size = new System.Drawing.Size(352, 257);
this.glassTabControl1.TabIndex = 0;
this.glassTabControl1.TabMinimumHeight = 25;
new GlassTabControlUI.TabPagesCollection().Add(this.glassTabPage1);
如您所见,最后一行没有任何意义,如果我将其替换为:
As you can see the last line makes no sense and if I replace it with:
this.glassTabControl1.TabPages.Add(this.glassTabPage1);
完美运作.
抱歉,这么长的帖子,我很想听听您对为什么生成该代码的看法.
PS:我尝试清洁溶液,重新启动VS等.
谢谢,
Alex
works perfectly.
Sorry for such a long post and I''m eager to hear your opinion on why that code is generated.
PS: I tried cleaning the solution, restarting VS, etc.
Thanks,
Alex
推荐答案
添加DesignerSerializationVisibility属性:
Add the DesignerSerializationVisibility attribute:
// the property
[Browsable(true)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public GlassTabPageCollection TabPages
{
get { return _tabList; }
set { _tabList = value; }
}
http://msdn.microsoft.com/en-us/library/system.componentmodel. designerserializationvisibilityattribute.aspx [^ ]
http://msdn.microsoft.com/en-us/library/system.componentmodel.designerserializationvisibilityattribute.aspx[^]
这篇关于VS 2010生成奇怪的代码.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!