. NET Component Programming (8) component documentdesigner (document designer)

Source: Internet
Author: User

Each component has not only the component designer, but also the component documentdesigner. But what is the difference between the two designers? I will tell you the difference by using a more common method. Component designer refers to the uidesigner presented when component is dragged to form or page container (figure 1 ); component documentdesigner refers to the root document designer of component (figure 2 ).

For example, there are two components named baseclass1 and class1, and class1 inherits from baseclass1. We designed documentdesigner for baseclass1, and the design items are invisible in the document designer of baseclass1, it is visible in class1.
The Code is as follows:
Baseclass1

Using system;
Using system. Collections. Generic;
Using system. text;
Using system. componentmodel;
Using system. componentmodel. design;
Using system. Windows. Forms. design;
Using system. Windows. forms;

Namespace classlibrary1
{
// Note typeof (irootdesigner ).
[Designer (typeof (baseclass1documentdesigner), typeof (irootdesigner)]
Public class baseclass1: Component
{
}

// Define documentdesigner.
Public class baseclass1documentdesigner: componentdocumentdesigner
{
Public baseclass1documentdesigner ()
{
Designerverb verb1 = new designerverb ("test1", new eventhandler (ontest1 ));
This. verbs. Add (verb1 );
}

Private void ontest1 (Object sender, eventargs E)
{
MessageBox. Show ("test1 ");
}
}
}

 

Class1

Using system;
Using system. componentmodel;
Using system. Collections. Generic;
Using system. diagnostics;
Using system. text;
Using system. componentmodel. design;
Using system. Windows. forms;

Namespace classlibrary1
{
[Designer (typeof (class1designer), typeof (idesigner)]
Public partial class class1: baseclass1
{
}

Public class class1designer: componentdesigner
{
Public class1designer ()
{
Designerverb verb2 = new designerverb ("Test2", new eventhandler (ontest2 ));
This. verbs. Add (verb2 );
}

Private void ontest2 (Object sender, eventargs E)
{
MessageBox. Show ("Test2 ");
}
}
}

The effect is as follows:
 

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.