fork download
  1. using System.Windows.Forms;
  2. using System.Windows.Forms.Design;
  3. using System.ComponentModel.Design;
  4. using System.ComponentModel;
  5. using System.Drawing;
  6.  
  7. // System.Design.dll の参照が必要です。
  8. // ClientProfile では追加できないので注意してください。
  9.  
  10. namespace WindowsFormsApplication1
  11. {
  12. [Designer(typeof(MyControlDesigner))]
  13. public class MyControl : FlowLayoutPanel
  14. {
  15. public MyControl()
  16. {
  17. this.Size = new Size(300, 200);
  18.  
  19. this.ChildPanel = new ChildPanel();
  20. this.ChildPanel.Size = new Size(100, 100);
  21. this.Controls.Add(this.ChildPanel);
  22. }
  23.  
  24. [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
  25. public ChildPanel ChildPanel { get; internal set; }
  26. }
  27. internal class MyControlDesigner : ParentControlDesigner
  28. {
  29. public override void Initialize(IComponent component)
  30. {
  31. base.Initialize(component);
  32. MyControl myControl = (MyControl)component;
  33. this.EnableDesignMode(myControl.ChildPanel, "ChildPanel");
  34. }
  35. protected override void OnPaintAdornments(PaintEventArgs pe)
  36. {
  37. base.OnPaintAdornments(pe);
  38. Rectangle rect = this.Control.ClientRectangle;
  39. rect.Inflate(-1, -1);
  40. using (Pen pen = new Pen(Color.Gray))
  41. {
  42. pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;
  43. pe.Graphics.DrawRectangle(pen, rect);
  44. }
  45. }
  46. }
  47.  
  48. [ToolboxItem(false)]
  49. [Designer(typeof(ChildPanelDesigner))]
  50. public class ChildPanel : FlowLayoutPanel { }
  51.  
  52. public class ChildPanelDesigner : ParentControlDesigner
  53. {
  54. public override SelectionRules SelectionRules
  55. {
  56. get
  57. {
  58. return base.SelectionRules & ~SelectionRules.Moveable;
  59. }
  60. }
  61.  
  62. protected override void OnPaintAdornments(PaintEventArgs pe)
  63. {
  64. base.OnPaintAdornments(pe);
  65. Rectangle rect = this.Control.ClientRectangle;
  66. rect.Inflate(-1, -1);
  67. using (Pen pen = new Pen(Color.Gray))
  68. {
  69. pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;
  70. pe.Graphics.DrawRectangle(pen, rect);
  71. }
  72. }
  73. public override bool CanBeParentedTo(IDesigner parentDesigner)
  74. {
  75. return (parentDesigner is MyControlDesigner);
  76. }
  77. }
  78. }
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty