Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

hi , I have a question regarding property in vb.net.

 

for ex:

 

i have a statusbar control in the form name statusBar and value text = "".

 

then i create the property as follows:

Public Property StatusText() as String
  Get
     Return statusBar.Text
  End Get
  Set(ByVal Value As String)
     statusBar.Text = Value
  End Set
End Property

 

after that, to call this property :

StatusText = "Ready"

 

What is the use of property in vb.net?

why can't we just type:

  statusBar.Text = "Ready"
  

instead of creating the property?

 

Some book say that property is very useful and important in vb.net but I do not see it. Please give me advice about this , Thanks.

Posted
The only reason that I can see why you would do it like that is so that you can set the StatusText property from outside of the form.

TT

(*_*)

 

There are 10 types of people in this world;

those that understand binary and those that don't.

  • *Gurus*
Posted

Exactly. Properties are an interface between private fields and the outside world. If you have a control that paints itself, you need a text property, so that when the user calls the Set method, you know to redraw your control.

 

For more info on properties, I suggest you read the documentation.

MVP, Visual Developer - .NET

 

Now you see why evil will always triumph - because good is dumb.

 

My free .NET Windows Forms Controls and Articles

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...