User Control as container at design time

前端 未结 3 492
醉梦人生
醉梦人生 2020-12-05 07:24

I\'m designing a simple expander control.

I\'ve derived from UserControl, drawn inner controls, built, run; all ok.

Since an inner Control is a Panel, I\'d l

3条回答
  •  遥遥无期
    2020-12-05 07:59

    In addition to the answer above. It is mentioned in the comments, that the user is able to drag the WorkingArea. My fix for that is to include the WorkingArea panel in another panel, setting it to Dock.Fill. To disallow the user to change it back, I have created a class ContentPanel that overrides and hides the Dock property:

    class ContentPanel : Panel
    {
        [Browsable(false)]
        public override DockStyle Dock
        {
            get { return base.Dock; }
            set { base.Dock = DockStyle.Fill; }
        }
    }
    

    For me, this makes it sufficiently safe. We are only using the control internally, so we mainly want to prevent developers from accidently dragging things around. There are certainly ways to mess it up anyway.

提交回复
热议问题