繁体   English   中英

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

[英]How can I tell Visual Studio to not populate a field in the designer code?

我有一个自定义控件,当我拖到窗体上时,创建以下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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM