How to: Debug. NET components/controls during design

Source: Internet
Author: User
This article mainly describes how to debug components during design. In most cases, developers use messgebox to pop up information for debugging, but cannot access the code. Therefore, this article is illustrated. This article references Microsoft's "drill: Debugging custom Windows Forms controls during design" in msdn. In view of its obscure Chinese translation, it is recommended that you refer to this article.

Background

You need to know the differences between components and controls, the general direction of component programming, and the services (components) provided by. Net to support component programming and design events.

If you are interested, refer:

. Net Control Programming-document

Step by step debugging

The debugging objects for component design are:
An object is the component we care about. The other is the component designer.

For example, a component mycomponet has an attribute. I need to debug it when setting the value.

    private string demoStringValue = null;        [Browsable(true)]        public string DemoString        {            get            {                return this.demoStringValue;            }            set            {                demoStringValue = value; //è¾ç½æ-点            }        }

Preparations
1. Create a library, create the mycomponent component, add the above Code, and compile it.
2. Add testmycomponent, a Windows application project for debugging.
3. Set the library project as the startup project, and set the startup of external programs in property debugging,
Set the location of:
For example:
D: \ Program Files \ Microsoft Visual Studio 9.0 \ common7 \ ide \ devenv.exe

Continue

1. Press F5 to start the debugging process. A new vs. Net instance is started. We reload this solution in the new.

4. In the windows application project, double-click form1 to open it.
5. Drag mycomponent to form1 In the toolbar,
6. On the properties page, change the value of the demostring attribute to good bye.
7. At this time, you should step into the position where the breakpoint is located.

We have introduced the debugging component itself.

Sometimes, we customize the designer to implement some specific functions.

For example, we want to capture the events that the component is added to and the events that the component is removed. The solution is to access the designed service.

Allows a widget or component to define the designer label.

To trigger the corresponding event in the designer, you must obtain the service object and mount the corresponding event.

The custom designer must inherit from controldesigner or componentdesigner.

Custom initialization and add a private method to initialize the service object:

Accessible services:

For example, the add or remove event of the control that we are concerned

Componentadded event

Set the breakpoint here and repeat the debugging action. The last two parts are different,

When we drag the control or component into form1, debugging enters the designer.

So far, the two types of debugging have ended.

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.