■ ParentControlDesigner 클래스를 사용해 디자이너 모드에서 편집 가능한 사용자 컨트롤을 만드는 방법을 보여준다.
▶ SampleControlDesigner.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
using System.ComponentModel; using System.Windows.Forms.Design; namespace TestProject { /// <summary> /// 샘플 컨트롤 디자이너 /// </summary> public class SampleControlDesigner : ParentControlDesigner { //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Public #region 초기화 하기 - Initialize(component) /// <summary> /// 초기화 하기 /// </summary> /// <param name="component">컴포넌트</param> public override void Initialize(IComponent component) { base.Initialize(component); SampleControl sampleControl = component as SampleControl; if(sampleControl != null) { base.EnableDesignMode(sampleControl.RootPanel, "RootPanel"); } } #endregion } } |
▶ SampleControl.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
using System.ComponentModel; using System.Windows.Forms; namespace TestProject { /// <summary> /// 샘플 컨트롤 /// </summary> [Designer(typeof(SampleControlDesigner))] public partial class SampleControl : UserControl { //////////////////////////////////////////////////////////////////////////////////////////////////// Field ////////////////////////////////////////////////////////////////////////////////////////// Public #region Field [Category("SampleControl"),Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Content)] public Panel RootPanel => this.rootPanel; #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - SampleControl() /// <summary> /// 생성자 /// </summary> public SampleControl() { InitializeComponent(); } #endregion } } |