Assign a value to the code generator when the custom property is unavailable

Source: Internet
Author: User

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;
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.