locked
How to get a Color Picker for a property? RRS feed

  • Question

  • User218686162 posted

    Hi, I would like to create a property that uses the Visual Studio color picker (just like ForeColor and BackColor).

    It seems I need something like this:

    [Editor(typeof(ColorTypeEditor),typeof(UITypeEditor)) ]

    But I am not able to find the correct syntax.

    I tried it without an editor and returning the type "Color", but that just generates a dropdown with all of the known color names for the property.  I would like the color picker to appear which allows you to see the colors and pick one.

    How can I do this?

    This is a C# web page.

    Thank you.

    Wednesday, February 24, 2010 3:50 PM

Answers

  • User-68639941 posted

    hi,

     if your property return type is Color then it will automatically shows the editor,else try with below attribute with the property

    [Editor("System.Drawing.Design.ColorEditor, System.Drawing.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor)), DebuggerDisplay("{NameAndARGBValue}")]

    hi, try by giving the below attributes

    [DefaultValue(typeof(Color), ""), TypeConverter(typeof(WebColorConverter))]

    and return type is Color

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, February 25, 2010 1:42 AM

All replies

  • User-68639941 posted

    hi,

     if your property return type is Color then it will automatically shows the editor,else try with below attribute with the property

    [Editor("System.Drawing.Design.ColorEditor, System.Drawing.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor)), DebuggerDisplay("{NameAndARGBValue}")]

    hi, try by giving the below attributes

    [DefaultValue(typeof(Color), ""), TypeConverter(typeof(WebColorConverter))]

    and return type is Color

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, February 25, 2010 1:42 AM
  • User218686162 posted

    Thanks for your reply.

    Having my return type as Color does not automatically show the editor for some reason.  This is in VS 2008.

    Adding the attribute you posted did work however.  Any ideas why just having color as the return type doesn't work?

    Thank you. 

    Thursday, February 25, 2010 7:44 AM
  • User218686162 posted

    Hi, your updated comment about

    [DefaultValue(typeof(Color), ""), TypeConverter(typeof(WebColorConverter))]

    and return type is Color

    works as well, and is cleaner.


    Thank you!

    Thursday, February 25, 2010 9:29 AM