Multimobile Development: Building Applications for any Smartphone
Problems overloading Text property in UserControl (designer issue)
Messages   Related Types
This message was discovered on microsoft.public.dotnet.framework.windowsforms.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.

GOG
GOOD ANSWER
I've trying to code a faily simple UserControl object and have run into a problem that I can't get around. I want my control to surface a "Text" property that can be used at both design and run time.

Here is the current code for that property:
        [Browsable(true)]
        public override string Text {
         get { return checkBox1.Text; }
         set { checkBox1.Text = value; }
         }

This "half-works". Using a test form, I can place my control and change the Text property via the designer, but the code to actually set the Text property is never written into the "InitializeComponent()" method of the form. If I change the name of the property to "TextXX" (and remove the override) it works as expected.

Do you know why this might be happening?
If not can you suggest a debugging strategy to determine what is going on?
Do you know of any texts/articles/cookbooks on building non-trival user controls?

Thanks All,
GOG
Reply to this message...
Vote that this is a GOOD answer... (186 votes from other users already)
 
 
    
Stoitcho Goutsev \(100\) [C# MVP] (VIP)
GOOD ANSWER
Hi GOG,

This is the way you should define your property

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

--
HTH
B\rgds
100 [C# MVP]

"GOG" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
> I've trying to code a faily simple UserControl object and have run into a
problem that I can't get around. I want my control to surface a "Text"
property that can be used at both design and run time.
[Original message clipped]

property is never written into the "InitializeComponent()" method of the
form. If I change the name of the property to "TextXX" (and remove the
override) it works as expected.
[Original message clipped]

Reply to this message...
Vote that this is a GOOD answer... (191 votes from other users already)
 
 
    
GOG
GOOD ANSWER
Fantastic!!!!
Thank you

I've been trying to figure that out for a while. I figured that there was an attribute for it, but couldn't even find a list of attributes to search through.
Do you know of a good "attribute reference"? (I figure it's in MSDN somewhere, but I have been able to tease it out yet, likely something simply i've missed).

Thanks again,
GOG
Reply to this message...
Vote that this is a GOOD answer... (195 votes from other users already)
 
 
    
GOG
GOOD ANSWER
I found it !
All those pesky attributes were hiding in the ComponentModel class (imagine that :-)
I made a list for others who might find this thread useful in the future (and who like myself are sometimes "document impaired")

Thanks again for your help.

List of attributes from System.CompenentModel

AmbientValueAttribute
Specifies the value to pass to a property to cause the property to get its value from another source. This is known as ambience. This class cannot be inherited.

BindableAttribute
Specifies whether a property is typically used for binding.

BrowsableAttribute
Specifies whether a property or event should be displayed in a Properties window.

CategoryAttribute
Specifies the name of the category in which to group the property or event when displayed in a System.Windows.Forms.PropertyGrid control set to Categorized mode.

DefaultEventAttribute
Specifies the default event for a component.

DefaultPropertyAttribute
Specifies the default property for a component.

DefaultValueAttribute
Specifies the default value for a property.

DescriptionAttribute
Specifies a description for a property or event.

DesignerAttribute
Specifies the class used to implement design-time services for a component.

DesignerCategoryAttribute
Specifies that the designer for a class belongs to a certain category.

DesignerSerializationVisibilityAttribute
Specifies the type of persistence to use when serializing a property on a component at design time.

DesignOnlyAttribute
Specifies whether a property can only be set at design time.

DesignTimeVisibleAttribute
DesignTimeVisibleAttribute marks a component's visibility. If DesignTimeVisibleAttribute.Yes is present, a
visual designer can show this component on a designer.

EditorAttribute
Specifies the editor to use to change a property. This class cannot be inherited.

EditorBrowsableAttribute
Specifies that a property or method is viewable in an editor. This class cannot be inherited.

ImmutableObjectAttribute
Specifies that an object has no subproperties capable of being edited.

InheritanceAttribute
Indicates whether the component associated with this attribute has been inherited from a base class. This class cannot be inherited.

InstallerTypeAttribute
Specifies the installer for a type that installs components.

LicenseProviderAttribute
Specifies the LicenseProvider to use with a class.

ListBindableAttribute
Specifies that a list can be used as a data source. A visual designer should use this attribute to determine whether to display a particular list in a data-binding picker. This class cannot be inherited.

LocalizableAttribute
Specifies whether a property should be localized.

MergablePropertyAttribute
Specifies that this property can be combined with properties belonging to other objects in a Properties window.

NotifyParentPropertyAttribute
Indicates that the parent property is notified when the value of the property that this attribute is applied to is modified. This class cannot be inherited.

ParenthesizePropertyNameAttribute
Indicates whether the name of the associated property is displayed with parentheses in the Properties window. This class cannot be inherited.

PropertyTabAttribute
Identifies the property tab or tabs to display for the specified class or classes.

ProvidePropertyAttribute
Specifies the name of the property that an implementor of IExtenderProvider offers to other components.

ReadOnlyAttribute
Specifies whether the property this attribute is bound to is read-only or read/write at design time.

RecommendedAsConfigurableAttribute
Specifies that the property can be used as an application setting.

RefreshPropertiesAttribute
Indicates how a designer refreshes when the associated property value changes. This class cannot be inherited.

RunInstallerAttribute
Specifies whether the Visual Studio .NET Custom Action Installer or the Installer Tool (Installutil.exe) should be invoked when the assembly is installed.

ToolboxItemAttribute
Represents an attribute of a toolbox item.

ToolboxItemFilterAttribute
Specifies the filter string and filter type to use for a toolbox item.

TypeConverterAttribute
Specifies what type to use as a converter for the object this attribute is bound to. This class cannot be inherited.

Reply to this message...
Vote that this is a GOOD answer... (197 votes from other users already)
 
 
 
System.ComponentModel.AmbientValueAttribute
System.ComponentModel.BindableAttribute
System.ComponentModel.BrowsableAttribute
System.ComponentModel.CategoryAttribute
System.ComponentModel.DefaultEventAttribute
System.ComponentModel.DefaultPropertyAttribute
System.ComponentModel.DefaultValueAttribute
System.ComponentModel.DescriptionAttribute
System.ComponentModel.DesignerAttribute
System.ComponentModel.DesignerCategoryAttribute
System.ComponentModel.DesignerSerializationVisibility
System.ComponentModel.DesignerSerializationVisibilityAttribute
System.ComponentModel.DesignOnlyAttribute
System.ComponentModel.DesignTimeVisibleAttribute
System.ComponentModel.EditorAttribute
System.ComponentModel.EditorBrowsableAttribute
System.ComponentModel.IExtenderProvider
System.ComponentModel.ImmutableObjectAttribute
System.ComponentModel.InheritanceAttribute
System.ComponentModel.InstallerTypeAttribute
System.ComponentModel.LicenseProvider
System.ComponentModel.LicenseProviderAttribute
System.ComponentModel.ListBindableAttribute
System.ComponentModel.LocalizableAttribute
System.ComponentModel.MergablePropertyAttribute
System.ComponentModel.NotifyParentPropertyAttribute
System.ComponentModel.ParenthesizePropertyNameAttribute
System.ComponentModel.PropertyTabAttribute
System.ComponentModel.ProvidePropertyAttribute
System.ComponentModel.ReadOnlyAttribute
System.ComponentModel.RecommendedAsConfigurableAttribute
System.ComponentModel.RefreshPropertiesAttribute
System.ComponentModel.RunInstallerAttribute
System.ComponentModel.ToolboxItemAttribute
System.ComponentModel.ToolboxItemFilterAttribute
System.ComponentModel.TypeConverterAttribute
System.EnterpriseServices.DescriptionAttribute
System.Web.UI.UserControl
System.Windows.Forms.PropertyGrid
System.Windows.Forms.UserControl




Ad
BootFX
Reliable and powerful .NET application framework.
iOS, Android and Windows Phone Development Training and Consultancy
Hosted by RackSRV Communications
 
Multimobile Development: Building Applications for any Smartphone
Copyright © AMX Software Ltd 2008-2010. Portions copyright © Matthew Baxter-Reynolds 2001-2010. All rights reserved.
Contact Us - Terms of Use - Privacy Policy - 4.0.30129.1734