How to enable the child control of the composite control to be supported during design

Source: Internet
Author: User

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 " );
}
}

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.