"Problem pending" Custom control design interface error, compile and run normally

Source: Internet
Author: User

"Problem Symptoms":

Custom controls are written and dragged onto a form to manipulate their properties, and when the form is opened for the second time, some messy errors are displayed, but the compilation is possible, and the operation is normal. As follows:

This error is seen more frequently, and there are other inexplicable errors.

"Problem not resolved":

Helpless, had to open the page of the Designer.cs and. resx, which did find some clues, as follows:

Points to the DataSource property of the custom control, it attempts to delete part of the. resx code. The result is unexpectedly ah, no problem, the designer again open and close all no problem, but the custom control removed and then pull again, the code automatically appears. Can't bear it. is still a DataSource problem, and then adds a line to the custom control's construction method: Datasource=null; The result is unexpectedly, the problem seems to be solved, the switch designer or deleted after the addition of nothing wrong, things seem to be over, But setting your own data source in the construction method is empty, and it seems like a wonderful alternative. This kind of solution is pass.

Since it is a datasource problem, then go to the custom control to find the problem.

          Public List<comboxitem> DataSource        {            getreturn  items;}             Set {items = value;}        }    

There seems to be no problem, so replace the datasource with automatic attributes, discard the use of the internal fields items, and then drag to drag the experiment, no fault. The problem seems clearer, the initial value of "items". Items as private fields, you can assign values in the constructor method, or you can assign values in the Load event. However, in this custom control, the "Private list<comboxitem> items=new list<comboxitem> (), which is assigned when items are defined," only opens up memory space, does not give the actual object. The problem has been solved to a certain extent, and now it is necessary to let the items field be used internally, to provide access to the outside, and finally to remove the initial value of items (that is, new), and the problem is solved (but this is not the effect I want).

"Reflection":

1. In the process of solving this problem, it is seen that a "filter" part of the operation is done through the DesignMode or site.designmode attribute, so that the control does not crash at the design interface. Rookie D Remember there is a feature (Attribute) tag control, the control is displayed only in the design interface, does not load the data related things (this is what I want to effect), but did not find (I do not know is wrong, or there is no). Refer to Http://www.cnblogs.com/wuhuacong/p/3508467.html for DesignMode

2. About features (attribute): Not much understanding, such as [Designtimevisible (false)] can make the control in the Toolbox hidden (for the use of incomprehensible, the control is not found in the toolbox, made not to use it);

[Category ("Appearance")] is the classification of the marked (control) attribute, which belongs to the appearance of the behavior or belongs to the data, or you can define a classification;

[Browsable (False)] marked properties are visible or not visible in the properties form

[Description (the text associated with the control)] Adds a description for the (Control) property of the tag, which can be viewed in the Properties form.

3. Custom controls inevitably provide some means of access to the outside world, often with attributes and events, events are not discussed in this section, and now the problem of attributes. properties are a safe and effective way to provide access to internal private fields (internal resources) for the outside world.

Automatic attributes (also called its self-implemented property) is a shortcut to add a property, enter prop, press ENTER, and then a template of the property is generated, only need to modify the property's type and property name is OK, through the code slice implementation, not what unusual operation.

The effect is as follows: public type type {get; set;} There is also a way to encapsulate existing fields into attributes, as well as shortcuts: Place the cursor after the field name (front, middle, or selected), a key combination ctrl+r, E, and then two times the carriage return (in the middle is preview, directly with the carriage return, no need to see). It is important to note that when an existing field is encapsulated as a property, the existing field or not to assign an initial value to avoid the above error. -----------------------------------------China (Yin) li (dang) Split line-------------------------------------

Rookie d This text does not have any advanced technology, cattle 13 theory, only from the simple and subtle place to find the reflection of the problem, the idea of solving the problem including the means are very young, the old birds laughed and smiled, the rookie of the Smile also laughed, originally this mentality is not individual (even right and wrong is not necessarily), if there is falsehood, Welcome to correct, rookie D look forward to progress.

This text does not from the substantive or large aspect to solve the problem in the title, just for a special case, if the reader has more ingenious ideas and methods, welcome to comment or contact me qq:1304679383.

Rookie D Hope this text is helpful to you.

"Problem pending" Custom control design interface error, compile and run normally

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.