How can I tell Visual Studio to not populate a fie

2019-06-21 19:14发布

I have a custom control that when I drag onto the form, creates the following designer.cs code:

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

I'd like it (Visual Studio) to completely ignore the .Color attribute and leave it be. How can I tell it to do that?

Thank you!

1条回答
一夜七次
2楼-- · 2019-06-21 19:25

You can derive a new class from the ColorPickerBackground class. Override (or new) the Color property and decorate with the attributes found in System.ComponentModel...

Take a look at these:

[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

查看更多
登录 后发表回答