If a composite control is composed of a toolstrept and a Textbox, how can we make toolstrsight available at design time? Can we add or delete a control like a common toolstript during design?
Setting toolstript to public cannot achieve the goal. A designer must be defined to serve the components during design.
[Designer ( Typeof (Mydesigner)]
Public Partial Class Usercontrol1: usercontrol
Mydesigner inherits from system. Windows. Forms. design.Controldesigner class, which provides a method "enabledesignmode ". It enables the design-time function of the Child control, but you need to expose the child control as the property of the main control.
AllCodeAs follows:
[Designer ( Typeof (Mydesigner)]
Public Partial Class Usercontrol1: usercontrol
{
Public Usercontrol1 ()
{
Initializecomponent ();
}
[Browsable ( False ), Designerserializationvisibility (designerserializationvisibility. Content)]
Public Toolstrip mytoolstrip
{
Get {Return This. Toolstrip1 ;}
}
}
Internal Class Mydesigner: controldesigner
{
Private Usercontrol1 mycontrol;
Public Override Void Initialize (icomponent component)
{
Base . Initialize (component );
// Record instance of control we're re Designing
Mycontrol = (Usercontrol1) component;
This . Enabledesignmode (mycontrol. mytoolstrip, " Mytoolstrip " );
}
}