今天,我决定在使用Visual Studio 2012时使用C#创建一个自定义的TextButton控件。 我非常喜欢我设计的样式,尽管它可能很简单。 然而,当我决定将我的完成组件移动到使用Visual Studio Designer的表单中时,遇到了一个问题。 尽管Text属性出现在属性列表中,但该属性实际上并没有在MainWindow.Designer.cs文件中更改。 下面是定义属性的代码:
[Category("Appearance")]
[Description("The text displayed by the control.")]
[Browsable(true), EditorBrowsable(EditorBrowsableState.Always)]
public override string Text
{
get
{
return Button.Text;
}
set
{
Button.Text = value;
}
}
这是我的MainWindow.Designer.cs文件在InitializeComponent方法中创建的代码:
this.Open = new UI.Controls.TextButton();
this.Open.Location = new System.Drawing.Point(9, 3);
this.Open.Name = "Open";
this.Open.Size = new System.Drawing.Size(112, 28);
this.Open.TabIndex = 4;
this.Open.Click += new System.EventHandler(this.OpenButton_Click);