如何告诉Visual Studio不填充设计器代码中的字段?

我有一个自定义控件,当我拖到窗体上时,创建以下designer.cs代码:

// // colorPickerBackground // this.colorPickerBackground.Color = Color.Empty; this.colorPickerBackground.Location = new System.Drawing.Point(256, 175); this.colorPickerBackground.Name = "colorPickerBackground"; this.colorPickerBackground.Size = new System.Drawing.Size(156, 21); this.colorPickerBackground.TabIndex = 17; this.colorPickerBackground.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(this.colorPicke 

我希望它(Visual Studio)完全忽略.Color属性并保留它。 我怎么能告诉它这样做?

谢谢!

您可以从ColorPickerBackground类派生一个新类。 覆盖(或新增)Color属性并使用System.ComponentModel中找到的属性进行修饰…

看看这些:

 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] public Color Color { get; set; } 

http://msdn.microsoft.com/en-us/library/system.componentmodel.designerserializationvisibilityattribute.aspx

http://msdn.microsoft.com/en-us/library/system.componentmodel.browsableattribute.aspx

http://msdn.microsoft.com/en-us/library/system.componentmodel.editorbrowsableattribute.aspx