all groups > vb.net controls > september 2004 >
You're in the

vb.net controls

group:

Deafult Value of a User Control Property ?


Deafult Value of a User Control Property ? eBob.com
9/27/2004 1:57:10 PM
vb.net controls:
I've created a User Control and given it a property using the folloing
code ...

<Description("AgeP (in days)"), _
DefaultValue(5)> _
Property AgeP() As Int32
Get
Return AgeP
End Get
Set(ByVal Value As Int32)
AgeP = Value
End Set
End Property


Note that the DefaultValue is 5. But when I drag my UserControl onto
a form the default value for AgeP (under Misc.) shows up as 0. Is
there something wrong with my code?

Re: Deafult Value of a User Control Property ? Ken Tucker [MVP]
9/27/2004 2:52:23 PM
Hi,

This is how i would do it.

Dim mintApeP as integer = 5

Property AgeP() As Int32
Get
Return mintAgeP
End Get
Set(ByVal Value As Int32)
mintAgeP = Value
End Set
End Property

Ken
----------------
[quoted text, click to view]
I've created a User Control and given it a property using the folloing
code ...

<Description("AgeP (in days)"), _
DefaultValue(5)> _
Property AgeP() As Int32
Get
Return AgeP
End Get
Set(ByVal Value As Int32)
AgeP = Value
End Set
End Property


Note that the DefaultValue is 5. But when I drag my UserControl onto
a form the default value for AgeP (under Misc.) shows up as 0. Is
there something wrong with my code?

Thanks, Bob

Re: Deafult Value of a User Control Property ? eBob.com
9/27/2004 9:05:48 PM
Thanks Ken. I'll be doing it your way in the future. I experimented
a bit and it doesn't seem to hurt to use ...

Dim mintAge As Int32 = 5
<Description("AgeP (in days)"), _
' DefaultValue(5)> _
Property Age() As Int32 ...

but what's the point? That's not just a remark. I am curious as to
what Description and DefaultValue attributes are used for? I can find
no documentation on these attributes.

Also learned that if I code ...

Dim mintAge As Int32 = 5
<Description("AgeP (in days)"), _
' DefaultValue(6)> _ ' < - NOTE 6 not 5
Property Age() As Int32 ...

Visual Studio still reports that the default is 5.

Thanks again for your help.

Bob



On Mon, 27 Sep 2004 14:52:23 -0400, "Ken Tucker [MVP]"
[quoted text, click to view]
Re: Deafult Value of a User Control Property ? Mick Doherty
9/28/2004 7:16:23 AM

[quoted text, click to view]

The Description Attribute sets the text that is shown in the pane below the
Property editor when the property is selected.

The DefaultValue Attribute assigns a value which will be applied on Reset of
the property in the property editor. You should also notice that when the
Value is not 5 then it will be Bold in the property editor and will be
serialized in the InititializeComponent() method.

[quoted text, click to view]
This results in the Initial Value being 6, but the Default Value is 5. Right
Click on the property in the Property Editor and choose reset and you wil
see that the value is set to 5 and is not shown in Bold.

--
Mick Doherty
http://dotnetrix.co.uk/nothing.html


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.742 / Virus Database: 495 - Release Date: 19/08/2004

Re: Deafult Value of a User Control Property ? eBob.com
9/28/2004 11:13:46 AM
Thank you very much Mick. I hadn't noticed the text in the pane below
the Property editor because I had its size squeezed down to
practically nothing. I can't imagine any reason for wanting Reset to
give a property a different value than its original default. But I am
REAL new to this stuff.

Thanks again for your help.

Bob


On Tue, 28 Sep 2004 07:16:23 +0100, "Mick Doherty"
<EXCHANGE#WITH@AND.REMOVE.SQUAREBRACKETS.[mdaudi100#ntlworld.com]>
[quoted text, click to view]
AddThis Social Bookmark Button