. NET component Programming (4) Debugging of user-defined property editor

Source: Internet
Author: User
Tags datetime

There are too many in the garden, the 2nd Chapter left the property DefaultValueAttribute problem solved, thanks to Colin Han's help, my understanding of defaultvalueattribute a bit misunderstood, The description for DefaultValueAttribute in MSDN is: "The visual designer can reset the values of members by using default values." The code generator can also use the default value to determine whether to generate code for members ", and I understand that in order to create a component, the default value is generated for the property marked with DefaultValueAttribute, as Colin Han explains:" This feature helps the IDE reduce code generation, and if you design a value with a DefaultValueAttribute property and a value of DefaultValue, the IDE will not generate codes for this attribute; The IDE automatically adds code to the InitializeComponent

An example is provided:

The Customer component has an age property, which is declared as follows

[Description("Customer's Age"), DefaultValue(20)]
        public int Age
        {
            get { return _age; }
            set { _age = value; }
        }

There is a form Form1 with a customer type of customer1 on the Form1, and at design time InitializeComponent () with the age set to 20,form1 is

private void InitializeComponent()
        {
            this.customer1 = new Components.Customer();
            //
            // customer1
            //
            this.customer1.Address = null;
            this.customer1.CreateTime = new System.DateTime(((long)(0)));
            this.customer1.Id = null;
            this.customer1.Sex = null;
        }

If the InitializeComponent () with age set to 40,form1 at design time is

private void InitializeComponent()
        {
            this.customer1 = new Components.Customer();
            //
            // customer1
            //
            this.customer1.Address = null;
            this.customer1.Age = 40;
            this.customer1.CreateTime = new System.DateTime(((long)(0)));
            this.customer1.Id = null;
            this.customer1.Sex = null;
        }

The second case is more than the first sentence this.customer1.Age = 40;

Originally this chapter prepared to speak Component Designer, but in the 3rd chapter of the comments chnking friends asked me, user-defined property editor how to debug the problem, I used to develop component in the process of using MessageBox to pop-up information, but LICHDR proposed a better way to monitor the process, so that users can customize the property editor debugging, I in VS 6.0 in this way debugging, But in the. NET environment I have never thought of, I think a lot of friends in the development process may also encounter such problems, at least I met, and walked a lot of detours, so it as a separate chapter to explain, here again thank Lichdr.

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.