1 Attachment(s)
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:
Attachment 83139
BB
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.
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