|
-
Mar 18th, 2011, 07:24 PM
#1
Numeric property with % symbol in Properties Window
A component I'm making has a public property that represents a percentage. Does anyone know how I can give it a % symbol in the Properties Window at design time in Visual Studio? I mean, like the Opacity property of a Windows Form:

BB
-
Mar 19th, 2011, 01:44 AM
#2
Re: Numeric property with % symbol in Properties Window
How a type or property behaves in the designer is pretty much always controlled by attributes from the System.ComponentModel namespace. As the documentation for the Form.Opacity property shows, it is the TypeConverterAttribute class that does this, using the OpacityConverter class. You could just use that same type converter but, given that your property doesn't represent opacity, you should probably create your own class. You can use .NET Reflector to see how the OpacityConverter is implemented.
-
Mar 19th, 2011, 07:19 AM
#3
Re: Numeric property with % symbol in Properties Window
Thank you JMC, that was exactly the hint I needed. I hadn't looked at TypeConverters before and I missed the fact that the Form.Opacity documentation in msdn gave me the answer I wanted. My own property is in fact an opacity, so in this case I can use OpacityConverter with a clear conscience. But now I know where to look in other cases.
BB
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|