As my program grows and grows, I find myself using Control.Tag more and more. I'm not quite sure why Microsoft put it there, but I find it very useful.
I was left wondering: what was their original purpose? What is considered acceptable and what is considered a taboo?
According to MSDN, Control.Tag "Gets or sets an object that contains data about the control."
In my calendar application, I save the actual Appointment object that represents the AppointmentControl . I suspect this is intentional use, and the MSDN example seems to confirm this, however I am also doing some more unusual things.
For example, when I have the back / next pair of buttons, and I want to go back to shutdown when we reach the beginning, and next to shutdown when we get to the end, then I will save the next button in the tag of the previous and previous buttons in the tag of the next. That way, I can always set ((Button)Tag).Enabled = true per click (because when you go back, the next button is explicitly disabled, and vice versa).
In addition, my calendar consists of a (visually) two-dimensional array of panels. I save a DateTime that corresponds to each panel in Panel.Tag , and when the user approaches to see time intervals in one day, the panels making up each time interval have a TimeSpan in their tag, which represents the slot start time.
So, I am wondering: What do you think is the most commonly used Tag? What more unusual Tag app did you use or see? Do you think that storing a linked object (as in the example with my back / next button) is โhackedโ?
Some people oppose the use of tags, suggesting that they are remnants of older languages. A common complaint is that itโs better to simply extend the control so that it contains a strongly typed object, rather than something arbitrary that you must use when using it. What do you think about it?