Control Properties of Type System.Drawing.Color

  • Thread starter Thread starter Nathan Sokalski
  • Start date Start date
N

Nathan Sokalski

I have a control with a property of type System.Drawing.Color. When I use
the control, the Property Grid in Visual Studio 2005 shows it, and even
gives me a dropdown list to select a color from. But it does not like the
value that gets put in the source. I get warnings like:

Generation of designer file failed: Cannot create an object of type
'System.Drawing.Color' from its string representation 'Green' for the
'BackgroundColor' property.

Am I not allowed to use colors as properties? Is there a property attribute
I need to add? It seems like a color should be a simple thing to add, since
there is only one value that needs specified in order choose it, and since
Visual Studio automatically gives me a list in the Property Grid to choose
from, I am assuming I am just missing something simple that I don't know
about. Any help would be appreciated. Thanks.
 
This is presumably a user control. What is your code for the
BackgroundColor property?
 
Actually, it is a custom control that inherits System.Web.UI.Control. My
code for the BackgroundColor property is:

Public WriteOnly Property BackgroundColor() As System.Drawing.Color
Set(ByVal value As System.Drawing.Color)
Me._backgroundcolor = value
End Set
End Property

Me._backgroundcolor is declared as:

Private _backgroundcolor As System.Drawing.Color

I know that my syntax for the property declaration is correct, I have used
it many times in other classes for other types (such as String, Integer,
etc.), just never with System.Drawing.Color. Any ideas? Thanks.
 
Actually, it is a custom control that inherits System.Web.UI.Control. My
code for the BackgroundColor property is:

Public WriteOnly Property BackgroundColor() As System.Drawing.Color
Set(ByVal value As System.Drawing.Color)
Me._backgroundcolor = value
End Set
End Property

Me._backgroundcolor is declared as:

Private _backgroundcolor As System.Drawing.Color

I know that my syntax for the property declaration is correct, I have used
it many times in other classes for other types (such as String, Integer,
etc.), just never with System.Drawing.Color. Any ideas? Thanks.

Since this is derived from a Web class, I can't really help much, being a
desktop guy, but I have to wonder: why WriteOnly?
 
Sometimes when developing my controls I don't add the Get's until later so
that I can see more of the properties on the screen at once. And since it is
a control intended primarily for declarative usage, it will allow me to use
it normally when testing. Yes, I do plan on adding the Get's before putting
it on my site, and maybe I do have a strange style, but most of the controls
I write are simply for the enjoyment, so who cares?
 
That looks like proper Property set code to me. What is the line of code
that the designer is generating in the Sub InitializeComponent for a color
that you select in the Properties Settings?
 
Back
Top