Results 1 to 4 of 4

Thread: Color property for a usercontorl... how do you define a default value.

  1. #1

    Thread Starter
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428

    Color property for a usercontorl... how do you define a default value.

    I have a TitleColor property declared in my usercontrol. I can't apply the DefaultValue attribute to my property however because it says the color value is not constant:
    VB Code:
    1. <DefaultValue(Color.Beige)> _
    2.     Public Property TitleColor() As Color
    3.         Get
    4.  
    5.         End Get
    6.         Set(ByVal Value As Color)
    7.  
    8.         End Set
    9.     End Property

    how do I get around this because I know it is possible. If you change a color value of a windows form then right click on the color in the properties window, there is a Reset option available... so there must be a way to set the default value, but how
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  2. #2
    Fanatic Member pax's Avatar
    Join Date
    Mar 2001
    Location
    Denmark
    Posts
    840
    Hi.

    You need to tell it what type of object it is.

    VB Code:
    1. <DefaultValue(GetType(Color),"Beige")> _
    2.     Public Property TitleColor() As Color
    3.         Get
    4.  
    5.         End Get
    6.         Set(ByVal Value As Color)
    7.  
    8.         End Set
    9.     End Property

    This will cause it to look up the "Beige" name in the Color enum.

    Hope it helps.
    I wish I could think of something witty to put in my sig...

    ...Currently using VS2013...

  3. #3

    Thread Starter
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    Originally posted by pax
    Hi.

    You need to tell it what type of object it is.

    VB Code:
    1. <DefaultValue(GetType(Color),"Beige")> _
    2.     Public Property TitleColor() As Color
    3.         Get
    4.  
    5.         End Get
    6.         Set(ByVal Value As Color)
    7.  
    8.         End Set
    9.     End Property

    This will cause it to look up the "Beige" name in the Color enum.

    Hope it helps.
    hahah I didnt think it'd be that simple thank you thank you
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  4. #4
    Fanatic Member pax's Avatar
    Join Date
    Mar 2001
    Location
    Denmark
    Posts
    840
    Hi.

    Any time .
    The great thing is, that you can use it on your own enums as well.

    VB Code:
    1. Public Enum MyEnums
    2.   A
    3.   B
    4.   C
    5. End Enum
    6.  
    7. <DefaultValue(GetType(MyEnums),"B")> Public Property MyProp as.....
    I wish I could think of something witty to put in my sig...

    ...Currently using VS2013...

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