Results 1 to 10 of 10

Thread: [HELP PLZ!!] I'm having a little problem setting the default value of a property

  1. #1

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

    Thumbs down [HELP PLZ!!] I'm having a little problem setting the default value of a property

    ahem, here's the property:

    VB Code:
    1. Private DEFAULT_FONT As Font = New Font ("Arial")
    2.  
    3. <DefaultValue(DEFAULT_FONT)> _
    4. Public Overrides Property Font() As Font
    5.         Get
    6.             Return mFont
    7.         End Get
    8.         Set(ByVal Value As Font)
    9.             mFont = Value
    10.         End Set
    11.     End Property


    It says that DEFAULT_FONT has to be a constant expression, but I cant declare a constant of type font.
    What should I do? I just want to have a default value for the font property
    Last edited by MrPolite; Feb 22nd, 2003 at 12:30 AM.
    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
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    You wouldn't want a default value for a font that you specify anyway. What if the user doesn't have that font installed? Your property will choke and errors will start to happen.

    What you want to do is get the default system font. I am looking for that right now.

  3. #3

    Thread Starter
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    Originally posted by hellswraith
    You wouldn't want a default value for a font that you specify anyway. What if the user doesn't have that font installed? Your property will choke and errors will start to happen.

    What you want to do is get the default system font. I am looking for that right now.
    I didnt think of that, heh

    ok but another problem, I want to do the exact same thing with Drawing.Color. Same problem. how would I fix that?
    (ie I have a TextColor property and I want that to have a default value)



    thanks for helping
    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

    Thread Starter
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    bump
    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!!

  5. #5
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Maybe it'd be easier to set the defaults in the constructor or some other place then.

  6. #6

    Thread Starter
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    well it's easy if I don't want to have a default property. I just want the user to be able to reset the color value to a default value. My problem is just with the DefaultValue attribute
    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!!

  7. #7
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Well it seems as if the DefaultValue attribute only works with less complex data types that can be constants so I don't think that will work. Although you can set the default value when its created in the constructor and you can still give the user the ability to set the color back to default, just not with the DefaultValue attribute.

  8. #8
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    Originally posted by Edneeis
    Well it seems as if the DefaultValue attribute only works with less complex data types that can be constants so I don't think that will work. Although you can set the default value when its created in the constructor and you can still give the user the ability to set the color back to default, just not with the DefaultValue attribute.
    But if you put it in the constructor, wouldn't any modification the app develper does to the properties be voided as soon as the object is created durring run time?

  9. #9
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    I don't think so I think the constructor only fires when the control is added to the form and if its just an object then it probably can't be set at designtime.

  10. #10
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    I tried this to set the defaultvalue for font and it worked but reseting does not work and i dont know why. I tried shouldserialize and reset methods but no success till now
    VB Code:
    1. Dim mfont As New Font("Times New Roman", 20.0!)
    2.     <DefaultValue(GetType(System.Drawing.Font), "Times New Roman, 20pt")> _
    3.     Public Overrides Property Font() As Font
    4.         Get
    5.             Return mfont
    6.         End Get
    7.         Set(ByVal Value As Font)
    8.              mfont = Value
    9.         End Set
    10.     End Property
    Last edited by Lunatic3; Feb 23rd, 2003 at 12:24 AM.

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