如何将自定义的控件设计成容器,这里介绍两种方法——

方法1:更改自定义控件的默认设计器,参照代码如下

 1 using System.ComponentModel;
 2 using System.ComponentModel.Design;
 3 using System.Windows.Forms;
 4 
 5 namespace DesignTime
 6 {
 7     [Designer("System.Windows.Forms.Design.ParentControlDesigner, System.Design", typeof(IDesigner))]
 8     class MyContainer : Control
 9     {
10     }
11 }

 

方法2:直接继承ContainerControl类,参照代码如下

1 using System.Windows.Forms;
2 
3 namespace DesignTime
4 {
5     class MyContainer : ContainerControl
6     {
7     }
8 }

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-11
  • 2021-12-27
猜你喜欢
  • 2021-05-16
  • 2021-11-22
  • 2021-09-17
  • 2021-07-26
  • 2021-05-25
  • 2021-06-24
  • 2021-10-22
相关资源
相似解决方案