[英]How to create an user control without graphic using c#
如何创建没有图形的用户控件?
当我使用Windows Form Control Library
创建用户控件时,看到以下命令行: public partial class UserControl1: UserControl
。 我的朋友告诉我,将UserControl1: UserControl
替换为UserControl1:Component,IDisposable
。 我不知道Component,IDisposable
是什么。
如果您查看一下可以放到窗体上的其他组件之一,这些组件没有自己的界面,那么您就可以看到朋友在说什么:
public class BackgroundWorker : Component
public class ErrorProvider : Component, IExtenderProvider, ISupportInitialize
public class Timer : Component
您可以轻松创建自己的:
public class MyVeryOwnComponent : Component
{
public string Setting1 { get; set; }
public string Setting2 { get; set; }
public void SomeImportantMethodYouCanCall()
{
// ...
}
}
并将其放在您的表单上:( 您必须先进行重建,才能使其显示在工具箱中)
您正在谈论的是“组件”,它是从System.ComponentModel.Component
派生的任何类。 控件是一种特殊类型的组件,它从类System.Windows.Forms.Control
派生。
如果您想创建自己的组件,只需使您的类从Component
派生,这就是您的朋友对:Component,IDisposable
所做的事情。 不需要IDisposable部分,因为Component
已经实现了IDisposeable
并且IDisposeable
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.