471,350 Members | 1,820 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,350 software developers and data experts.

User control properties--can't override base

I'm having trouble implementing a UserControl base property in a user
control that I am writing. My user control wraps a group box that contains
several radio buttons. I want to wire the user control's Text property to
the group box's Text property, like this:

[Browsable(true)]
public override string Text
{
get { return groupBox1.Text; }
set { groupBox1.Text = value; }
}

The property works fine at design time--I can set the user control's Text
property from a host form, and the value I type in appears as the caption
for the user control's group box. But the value is lost when the host
application is launched. At runtime, the group box shows its default value.

I can fix the problem by changing the name of the user control property from
"Text' to something else, like 'Caption'. Then the design time value
persists just fine to run time. But I'd really like to use the name 'Text'
for the user control property, to remain consistent with .NET conventions.

Is this problem common? What do I need to do to be able to use the name
'Text'? Thanks in advance for your help.

--
David Veeneman
Foresight Systems
Feb 16 '06 #1
2 4097
You'll need to add more attributes to the Text property. Particularly, it
sounds like the "DesignerSerializationVisibility" attribute is what is
causing the problem. See the link to the archive below for the attributes
that you'll need.
http://groups.google.com/group/micro...cb94cfe5?hl=en

--
Tim Wilson
..NET Compact Framework MVP

"David Veeneman" <da****@nospam.com> wrote in message
news:e3**************@TK2MSFTNGP11.phx.gbl...
I'm having trouble implementing a UserControl base property in a user
control that I am writing. My user control wraps a group box that contains
several radio buttons. I want to wire the user control's Text property to
the group box's Text property, like this:

[Browsable(true)]
public override string Text
{
get { return groupBox1.Text; }
set { groupBox1.Text = value; }
}

The property works fine at design time--I can set the user control's Text
property from a host form, and the value I type in appears as the caption
for the user control's group box. But the value is lost when the host
application is launched. At runtime, the group box shows its default value.
I can fix the problem by changing the name of the user control property from "Text' to something else, like 'Caption'. Then the design time value
persists just fine to run time. But I'd really like to use the name 'Text'
for the user control property, to remain consistent with .NET conventions.

Is this problem common? What do I need to do to be able to use the name
'Text'? Thanks in advance for your help.

--
David Veeneman
Foresight Systems

Feb 16 '06 #2
Thanks, Tim! That solved the problem.
Feb 16 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Chris Millar | last post: by
4 posts views Thread by patrick_a | last post: by
5 posts views Thread by Marcel Gelijk | last post: by
5 posts views Thread by Ben | last post: by
1 post views Thread by David Hearn | last post: by
2 posts views Thread by Xavier | last post: by
reply views Thread by XIAOLAOHU | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.