Creating a Custom Color Property list

M

Martin Dobson

Basically I can't figure out for the life of me how to display a custom list of colors in the property window. I have a property called ForeColor() which I want to use a custom list of colors which I have built as a structure. I mimiced the design of system.drawing.color to do this but it doesn't work. I get the following error:

"Value of type 'MBHC.WebCustCtls.Design.Color' cannot be converted to 'System.Drawing.Color'."

I am trying to build a custom typeconverter to avoid this but I seem to be going round in circles. Basically instead of showing the standard color picklist at design-time I want to show a custom list of only colors I specify. Here is my color structure, at present I am trying to display one color in the list. Once working I will want to list multiple different custom colors.

Public Structure Color
Private _DefaultColor As System.Drawing.Color

Public Shared ReadOnly Property NHSBlue() As System.Drawing.Color
Get
Return ColorTranslator.FromHtml("#0066CC")
End Get
End Property

Public Shared ReadOnly Property DefaultColor() As System.Drawing.Color
Get
Return ColorTranslator.FromHtml("#990000")
End Get
End Property
End Structure

Any suggestions?

Thanks in advance!
 
J

John Saunders

Martin Dobson said:
Basically I can't figure out for the life of me how to display a custom
list of colors in the property window. I have a property called ForeColor()
which I want to use a custom list of colors which I have built as a
structure. I mimiced the design of system.drawing.color to do this but it
doesn't work. I get the following error:
"Value of type 'MBHC.WebCustCtls.Design.Color' cannot be converted to 'System.Drawing.Color'."

I am trying to build a custom typeconverter to avoid this but I seem to be
going round in circles. Basically instead of showing the standard color
picklist at design-time I want to show a custom list of only colors I
specify. Here is my color structure, at present I am trying to display one
color in the list. Once working I will want to list multiple different
custom colors.
Public Structure Color
Private _DefaultColor As System.Drawing.Color

Public Shared ReadOnly Property NHSBlue() As System.Drawing.Color
Get
Return ColorTranslator.FromHtml("#0066CC")
End Get
End Property

Public Shared ReadOnly Property DefaultColor() As System.Drawing.Color
Get
Return ColorTranslator.FromHtml("#990000")
End Get
End Property
End Structure

Any suggestions?


Martin,

I recommend first of all that you stop using your own structure and instead
use System.Drawing.Color. Then you want to add a custom TypeConverter
derived from EnumConverter - to the property. That TypeConverter would
restrict the list of colors to only those that you want. You can also add
your own UITYpeEditor with the EditorAttribute, so that a dropdown is
displayed instead of the standard color-picker.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top