Text property in custom control not persisted

R

Rob Richardson

Greetings!

A few days ago, I asked how to get a property named "Text" to appear in the
Properties window for a control I developed. It was being hidden by the
Text property of the UserControl class, which was being hidden. Someone was
kind enough to post code very similar to the following, which is what I'm
using:

[EditorBrowsable(EditorBrowsableState.Always),
Browsable(true),
// DesignerSerializationVisibility(DesignerSerializationVisibility.Visible),
DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
Bindable(BindableSupport.Yes)]
public override string Text
{
get
{
return lblMain.Text;
}
set
{
try
{
lblMain.Text = value;
}
catch (Exception ex)
{
throw;
}
}
}

The Text property is accessible in the Properties window. However, if I
drop one of these controls onto a form, change the Text property, save the
form, close it, and reopen it, the Text property has its default value
instead of what I just entered. If I look in InitializeComponent(), I don't
see the expected "this.MyControl.Text = "What It's Supposed To Be" " line.
I tried changing the DesignerSerializationVisiblity attribute as you see
above, but it didn't help. What do I have to do?

Thanks very much!

RobR
 
T

Tim Wilson

Because the property is just a simple type, you should just need
"DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)".
Try posting the entire code file for your UserControl and I'll compile it
and see if it does the same thing at my end.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top