Control Properties of Type System.Drawing.Color

Discussion in 'ASP .Net' started by Nathan Sokalski, Oct 27, 2008.

  1. 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.
    --
    Nathan Sokalski

    http://www.nathansokalski.com/
     
    Nathan Sokalski, Oct 27, 2008
    #1
    1. Advertising

  2. Nathan Sokalski

    James Hahn Guest

    This is presumably a user control. What is your code for the
    BackgroundColor property?

    "Nathan Sokalski" <> wrote in message
    news:e0qVQS$...
    >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.
    > --
    > Nathan Sokalski
    >
    > http://www.nathansokalski.com/
    >
     
    James Hahn, Oct 27, 2008
    #2
    1. Advertising

  3. 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.
    --
    Nathan Sokalski

    http://www.nathansokalski.com/

    "James Hahn" <> wrote in message
    news:u9lfP2$...
    > This is presumably a user control. What is your code for the
    > BackgroundColor property?
    >
    > "Nathan Sokalski" <> wrote in message
    > news:e0qVQS$...
    >>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.
    >> --
    >> Nathan Sokalski
    >>
    >> http://www.nathansokalski.com/
    >>

    >
     
    Nathan Sokalski, Oct 27, 2008
    #3
  4. Nathan Sokalski

    Jeff Johnson Guest

    "Nathan Sokalski" <> wrote in message
    news:er%...

    > 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?
     
    Jeff Johnson, Oct 27, 2008
    #4
  5. 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?
    --
    Nathan Sokalski

    http://www.nathansokalski.com/

    "Jeff Johnson" <> wrote in message
    news:...
    > "Nathan Sokalski" <> wrote in message
    > news:er%...
    >
    >> 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?
    >
     
    Nathan Sokalski, Oct 27, 2008
    #5
  6. Nathan Sokalski

    James Hahn Guest

    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?

    "Nathan Sokalski" <> wrote in message
    news:er%...
    > 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.
    > --
    > Nathan Sokalski
    >
    > http://www.nathansokalski.com/
    >
     
    James Hahn, Oct 27, 2008
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sreejumon[MVP]

    convert hex to System.Drawing.Color

    Sreejumon[MVP], Jun 27, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    2,574
    Sreejumon[MVP]
    Jun 27, 2003
  2. Ken Cox [Microsoft MVP]

    Re: convert hex to System.Drawing.Color

    Ken Cox [Microsoft MVP], Jun 27, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    698
    Ken Cox [Microsoft MVP]
    Jun 27, 2003
  3. tshad
    Replies:
    10
    Views:
    15,054
    tshad
    Jan 12, 2005
  4. PJ6
    Replies:
    4
    Views:
    4,927
  5. Replies:
    1
    Views:
    686
    Kevin Spencer
    Jan 9, 2006
Loading...

Share This Page