사용자 정의 컨트롤에서 디자인 지원 활성화
Windows Forms 개발 영역에서 사용자 정의 컨트롤은 사전 정의된 컨트롤과 동일한 디자인 기능이 부족한 경우가 많습니다. 그 안에 포함될 때. 이는 사용자 정의된 목록 보기의 열 크기 조정과 같은 기능을 디자인 모드에서 액세스할 수 없는 경우 특히 실망스러울 수 있습니다. 그러나 사용자 정의 디자이너를 만들면 이러한 제한을 극복할 수 있습니다.
UserControl의 기본 디자이너인 ControlDesigner에는 포함된 컨트롤과 상호 작용하는 데 필요한 기능이 부족합니다. 이 문제를 해결하려면 ControlDesigner에서 상속하고 사용자 지정 컨트롤 내에서 원하는 컨트롤에 대한 디자인 지원을 구체적으로 활성화하는 사용자 지정 디자이너를 만들 수 있습니다.
이를 달성하려면 다음 단계를 따르세요.
아래 코드는 이 접근 방식을 보여줍니다.
using System; using System.ComponentModel; using System.Drawing; using System.Windows.Forms; using System.Windows.Forms.Design; // Note: add reference required: System.Design.dll namespace WindowsFormsApplication1 { [Designer(typeof(MyDesigner))] // Note: custom designer public partial class UserControl1 : UserControl { public UserControl1() { InitializeComponent(); } // Note: property added [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)] public ListView Employees { get { return listView1; } } } // Note: custom designer class added class MyDesigner : ControlDesigner { public override void Initialize(IComponent comp) { base.Initialize(comp); var uc = (UserControl1)comp; EnableDesignMode(uc.Employees, "Employees"); } } }
맞춤 디자이너를 생성하면 사용자 정의 컨트롤의 디자인 기능을 확장하여 열 크기 조정과 같은 기능을 활성화할 수 있습니다. UserControls에 포함된 ListView 컨트롤.
위 내용은 사용자 지정 Windows Forms 컨트롤에 포함된 컨트롤에 대한 디자인 타임 지원을 활성화하려면 어떻게 해야 합니까?의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!