【问题标题】:In .NET, how do you make a customized control that does not display on the windows form?在 .NET 中,如何制作一个不显示在 windows 窗体上的自定义控件?
【发布时间】:2011-04-17 02:34:14
【问题描述】:

如何制作不显示在 windows 窗体上的自定义控件,如 SerialPort 或 BackgroundWorker 或 ImageList 控件?

【问题讨论】:

    标签: c# .net winforms custom-controls


    【解决方案1】:

    继承自 Component 而不是 Control。

    【讨论】:

      【解决方案2】:

      向您的项目添加一个新类并粘贴如下所示的代码。编译。将新组件从工具箱顶部拖放到表单上。根据需要进行修饰。

      using System;
      using System.ComponentModel;
      
      [DefaultProperty("Aardvark")]
      class MyFoo : Component {
          public MyFoo() { }
          public MyFoo(IContainer container) { container.Add(this); }
      
          [DefaultValue(0)]
          public int Aardvark { get; set; }
      }
      

      【讨论】:

        【解决方案3】:

        您可以从 System.ComponentModel.Component 类派生而不是从 Control 派生。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2019-10-08
          • 2017-10-19
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多