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

5 c# 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
Run Code Online (Sandbox Code Playgroud)

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

谢谢!

csh*_*net 3

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

看看这些:

[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
public Color Color { get; set; }
Run Code Online (Sandbox Code Playgroud)

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