如何将用户控件中的子控件暴露成属性

最近有一个想法想将几种控件组合成一个用户控件,但有又想要子控件暴露成属性让使用者在设计界面完全的控制子控件。

于是就动手写实例:

 

View Code
public partial class LabelTextbox : UserControl

    {

        public LabelTextbox()

        {

            InitializeComponent();

        }



        [

           Category("Appearance"),

           Browsable(true),

           Description("设置Label")

        ]

        public DevComponents.DotNetBar.LabelX LabelPart

        {

            get

            {

                return this.labelx;

            }



            set

            {

                this.labelx = value;

            }

        }





        [

           Category("Appearance"),

           Browsable(true),

           Description("设置Textbox")

        ]

        public DevComponents.DotNetBar.Controls.TextBoxX TextBoxPart

        {

            get

            {

                return this.textboxx;

            }



            set

            {

                this.textboxx = value;

            }

        }

    }

 

满心欢喜以为成功
如何将用户控件中的子控件暴露成属性

结果设置的属性后根本没有生成相应代码。

受教育后材知道要:

 

View Code
    public partial class LabelTextbox : UserControl

    {

        public LabelTextbox()

        {

            InitializeComponent();

        }



        [

           Category("Appearance"),

           Browsable(true),

           Description("设置Label"),

           DesignerSerializationVisibility(DesignerSerializationVisibility.Content)

        ]

        public DevComponents.DotNetBar.LabelX LabelPart

        {

            get

            {

                return this.labelx;

            }



            set

            {

                this.labelx = value;

            }

        }





        [

           Category("Appearance"),

           Browsable(true),

           Description("设置Textbox"),

           DesignerSerializationVisibility(DesignerSerializationVisibility.Content)

        ]

        public DevComponents.DotNetBar.Controls.TextBoxX TextBoxPart

        {

            get

            {

                return this.textboxx;

            }



            set

            {

                this.textboxx = value;

            }

        }

    }


一个很简单的设置做个笔记。

 

你可能感兴趣的:(用户)