TAG Property

  • Thread starter Thread starter c_shah
  • Start date Start date
C

c_shah

Can someone please explain to me the purpose of the tag property for
WindowsForm controls such as a TEXTBOX? What is the benefit of using
this
property if any?
 
It's just a convenient holding place to store some bit of data or
object that you want to associate with the control.
 
The Tag property is datatype of Object, which means it can be any
datatype. It's purpose is to allow you to store some information that
is related to the control it is a property of, and since it is an
Object, this information can be of any form, a boolean, a string, a
collection of anything, etc.
 
It's there so you can associate arbitrary data with the control. Then,
whenever you need that piece of information, you can just get the object
from the Tag property and examine it.
 
c_shah said:
Can someone please explain to me the purpose of the tag property for
WindowsForm controls such as a TEXTBOX? What is the benefit of using
this
property if any?

Check out the documentation for 'Control.Tag', which mentions some use
cases.
 
(e-mail address removed) wrote in
The Tag property is datatype of Object, which means it can be any
datatype. It's purpose is to allow you to store some information that
is related to the control it is a property of, and since it is an
Object, this information can be of any form, a boolean, a string, a
collection of anything, etc.

I'm only just starting to read up on vb.net and c# - work is a vb6
shop...

I was under the impression that dotnet controls didn't support the tag
property - I take either I was wrong, or this has changed?

Am I really able to use a value type in an object property? I wasn't
aware that dotnet supported autoboxing either...

Martin.
 
Martin,
| I was under the impression that dotnet controls didn't support the tag
| property - I take either I was wrong, or this has changed?
..NET Windows Forms have supported the Tag property on Control since version
1.0

| Am I really able to use a value type in an object property? I wasn't
| aware that dotnet supported autoboxing either...

Yes, .NET has always supported autoboxing. However you need to use CType or
DirectCast to "unbox" if you are using Option Strict On.


--
Hope this helps
Jay B. Harlow [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net


| (e-mail address removed) wrote in
| |
| > The Tag property is datatype of Object, which means it can be any
| > datatype. It's purpose is to allow you to store some information that
| > is related to the control it is a property of, and since it is an
| > Object, this information can be of any form, a boolean, a string, a
| > collection of anything, etc.
|
| I'm only just starting to read up on vb.net and c# - work is a vb6
| shop...
|
| I was under the impression that dotnet controls didn't support the tag
| property - I take either I was wrong, or this has changed?
|
| Am I really able to use a value type in an object property? I wasn't
| aware that dotnet supported autoboxing either...
|
| Martin.
 
I was under the impression that dotnet controls didn't support the tag
property - I take either I was wrong, or this has changed?

The first beta of .Net 2002 didn't have it but programmers required it.

--


HTH

Éric Moreau, MCSD, Visual Developer - Visual Basic MVP
Conseiller Principal / Senior Consultant
Concept S2i inc. (www.s2i.com)
http://emoreau.s2i.com/
 
Back
Top