In winforms programming, we often use usercontrol or write our own control. However, when we define an attribute for control, users of the control do not want to assign values to this property of the control through the designer. A more obvious problem is that the designer generates the default value assignment code for this attribute. Sometimes, such a value assignment Code will make the control and other controls or windows that use the control unable to be opened in the designer. This problem can be solved by adding the browsable and designerserializationvisibility attributes to this attribute.
The sample code is as follows:
// Remember to use using system. componentmodel;
Private decimal m_customerid;
// Browsable makes this property invisible to the property display window, so that the control user cannot use the designer to assign values to this property
[Browsable (false)]
// Make the designer unable to see this attribute and do not generate the default value assignment code for this attribute
[Designerserializationvisibility (designerserializationvisibility. Hidden)]
Public decimal customerid
{
Get
{
Return m_customerid;
}
Set
{
M_customerid = value;
}
}