UserControl Shows Property in Visual Studio Designer, But Property Is Not Changed
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)]
Noah Crowley
I am a software engineer studying computer science at Case Western Reserve University who is interested in artificial intelligence and game development.
Updated on July 25, 2022Comments
-
Noah Crowley almost 2 years
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);
-
Pedro77 almost 6 yearsThe designer still does not add the overwritten property to MyControl.Designer.cs file. I change the value using Properties windows, the designer shows it, but after rebuilt or close/open the [designe] it is gone.
-
Pedro77 almost 6 yearsIt seem you have to add base.Text = value;. It is working now. From: stackoverflow.com/questions/6915933/…