using System.Windows.Forms; using System.Windows.Forms.Design; using System.ComponentModel.Design; using System.ComponentModel; using System.Drawing; // System.Design.dll の参照が必要です。 // ClientProfile では追加できないので注意してください。 namespace WindowsFormsApplication1 { [Designer(typeof(MyControlDesigner))] public class MyControl : FlowLayoutPanel { public MyControl() { this.Size = new Size(300, 200); this.ChildPanel = new ChildPanel(); this.ChildPanel.Size = new Size(100, 100); this.Controls.Add(this.ChildPanel); } [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)] public ChildPanel ChildPanel { get; internal set; } } internal class MyControlDesigner : ParentControlDesigner { public override void Initialize(IComponent component) { base.Initialize(component); MyControl myControl = (MyControl)component; this.EnableDesignMode(myControl.ChildPanel, "ChildPanel"); } protected override void OnPaintAdornments(PaintEventArgs pe) { base.OnPaintAdornments(pe); Rectangle rect = this.Control.ClientRectangle; rect.Inflate(-1, -1); using (Pen pen = new Pen(Color.Gray)) { pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash; pe.Graphics.DrawRectangle(pen, rect); } } } [ToolboxItem(false)] [Designer(typeof(ChildPanelDesigner))] public class ChildPanel : FlowLayoutPanel { } public class ChildPanelDesigner : ParentControlDesigner { public override SelectionRules SelectionRules { get { return base.SelectionRules & ~SelectionRules.Moveable; } } protected override void OnPaintAdornments(PaintEventArgs pe) { base.OnPaintAdornments(pe); Rectangle rect = this.Control.ClientRectangle; rect.Inflate(-1, -1); using (Pen pen = new Pen(Color.Gray)) { pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash; pe.Graphics.DrawRectangle(pen, rect); } } public override bool CanBeParentedTo(IDesigner parentDesigner) { return (parentDesigner is MyControlDesigner); } } }