Results 1 to 3 of 3

Thread: Numeric property with % symbol in Properties Window

  1. #1

    Thread Starter
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    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:

    Name:  percentProperty.jpg
Views: 142
Size:  9.8 KB

    BB

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    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
  •  



Click Here to Expand Forum to Full Width