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.