[英]How to create an user control without graphic using c#
How to create an user control without graphic? 如何创建没有图形的用户控件?
When I create an user control using Windows Form Control Library
, I saw this command line: public partial class UserControl1: UserControl
. 当我使用Windows Form Control Library
创建用户控件时,看到以下命令行: public partial class UserControl1: UserControl
。 My friend told me to replace UserControl1: UserControl
with UserControl1:Component,IDisposable
. 我的朋友告诉我,将UserControl1: UserControl
替换为UserControl1:Component,IDisposable
。 I don't know what Component,IDisposable
is. 我不知道Component,IDisposable
是什么。
You can see what your friend is talking about if you take a look at one of the other components you can drop onto your Form that don't have their own interface: 如果您查看一下可以放到窗体上的其他组件之一,这些组件没有自己的界面,那么您就可以看到朋友在说什么:
public class BackgroundWorker : Component
public class ErrorProvider : Component, IExtenderProvider, ISupportInitialize
public class Timer : Component
You can easily create your own: 您可以轻松创建自己的:
public class MyVeryOwnComponent : Component
{
public string Setting1 { get; set; }
public string Setting2 { get; set; }
public void SomeImportantMethodYouCanCall()
{
// ...
}
}
And drop it on your Form: (you'll have to rebuild first, to get it to show in the Toolbox) 并将其放在您的表单上:( 您必须先进行重建,才能使其显示在工具箱中)
What you are talking about is a "Component" which is any class derived from System.ComponentModel.Component
. 您正在谈论的是“组件”,它是从System.ComponentModel.Component
派生的任何类。 A control is a special type of component which derives from the class System.Windows.Forms.Control
. 控件是一种特殊类型的组件,它从类System.Windows.Forms.Control
派生。
If you want to make your own component just make your class derive from Component
, which is what your friend did with the :Component,IDisposable
. 如果您想创建自己的组件,只需使您的类从Component
派生,这就是您的朋友对:Component,IDisposable
所做的事情。 The IDisposable part was not needed because Component
already implements IDisposeable
and could be left off. 不需要IDisposable部分,因为Component
已经实现了IDisposeable
并且IDisposeable
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.