When I see my company working code, I sometimes see the code "Tag" member of Controls. My co-workers use it as a name tag. But the Controls have already a "Text", "Name" thingy properties. When I see the code, It looks fine to call the Controls with other properties.
I feel somewhat the "Tag" property is not for use of only giving the Control a specific name. So I looked up MSDN for information about it.
They say "Tag" is an Object that can store any data like class. And get the data fast from the tag property. I want to know when is the case should a programmer use it for? Can anyone help me with an example situation and codes?
By the way what are those attributes for? It seems those make the tag more special.
[System.ComponentModel.Bindable(true)]
[System.ComponentModel.TypeConverter(typeof(System.ComponentModel.StringConverter))]
public object Tag { get; set; }
CodePudding user response:
The tag can be used for anything you like, common use cases
- when a lot of controls share the same click handler
- tag on list / tree items that let you associate data with the clicked object (a customer object in a list of customers say)
The name nor text is usable in the second case