Total .NET Analyzer Rule Documentation  

ControlTag Rule

Avoid using the Tag property for controls.

Remarks

A control's Tag property allows you to associate values with controls. This property was useful in prior versions of Visual Basic to allow quick data accessibility, however .NET offers a more effective and efficient way of doing this. Instead of using the Tag property, consider using inheritance to extend components with your own properties. Inheritance allows you to add as many properties as you need, and to make those properties strongly typed.

Resolution

Instead of using the Tag property, use inheritance to extend the control. The following code example inherits from the Button control, and adds a new property called NewProp:

' VB
Public Class CustomButton
Inherits System.Windows.Forms.Button
Private NewProp As Integer
Property ButtonValue() As Integer
Get
Return NewProp
End Get
Set(ByVal Value As Integer)
NewProp = Value
End Set
End Property
End Class

// C#
public class CustomButton : System.Windows.Forms.Button
{
int NewProp;
int ButtonValue
{
get
{
return NewProp;
}
set
{
NewProp = value;
}
}
}

See Also

Control.Tag Property

Inheriting from Existing Windows Forms Controls