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: