Default value for Component property

  • Thread starter Thread starter Mike
  • Start date Start date
M

Mike

I have added some properties for my component and want to set the
default properties so they show the defaults when the component is
dropped on a form.

For example, should one property

Public Class WildcatComponent

Private Shared _ServerHost As String = "HDEV21"

<System.ComponentModel.DefaultValue("LocalHost")> _
Public Property ServerHost() As String
Get
Return _ServerHost
End Get
Set(ByVal value As String)
_ServerHost = value
End Set
End Property

End function

When I compile and add it to the toolbox and then in a test form
dropped the component, I am seeing a BLANK for this field. I am
expecting to see in the property editor

ServerHost: LocalHost

But its blank.

What am I missing here in setting the default.

--
 
Solved. Hmmm, its working now, I don't know why it didn't before.
but this time I am deleting the component first from the test form,
recompile the dll and drop it back in.

It works without the attribute. The initializer is all that is needed:

Private Shared _ServerHost As String = "LocalHost"
Public Property ServerHost() As String
Get
Return _ServerHost
End Get
Set(ByVal value As String)
_ServerHost = value
End Set
End Property

So whats the purpose of?

<System.ComponentModel.DefaultValue("LocalHost")>

thanks
 
Solved. Hmmm, its working now, I don't know why it didn't before.
but this time I am deleting the component first from the test form,
recompile the dll and drop it back in.

It works without the attribute. The initializer is all that is needed:

Private Shared _ServerHost As String = "LocalHost"
Public Property ServerHost() As String
Get
Return _ServerHost
End Get
Set(ByVal value As String)
_ServerHost = value
End Set
End Property

So whats the purpose of?

<System.ComponentModel.DefaultValue("LocalHost")>

thanks
 
Back
Top