So today, I decided to create a custom TextButton control in C# using Visual Studio 2012. I quite like the design I've made, simple as it may be. However, when I decided I would move my completed component into a form using the Visual Studio Designer, I ran into a snag. Although the Text property shows up in the properties list, the property is not not actually being changed in the MainWindow.Designer.cs file. Below is the code that defines the property:
[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;
}
}
And here is the code that my MainWindow.Designer.cs file is creating in the InitializeComponent method:
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);
Part of the problem is that you are overriding the UserControl's
Text
Property. If you name your property another name besides Text
such as myText
it will work. In order to fix the problem you have using Text
try adding the DesignerSerializationVisibility
Attribute to your Property, that should take care of it.
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With