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
. My friend told me to replace UserControl1: UserControl
with UserControl1:Component,IDisposable
. I don't know what Component,IDisposable
is.
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
. A control is a special type of component which derives from the class 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
. The IDisposable part was not needed because Component
already implements IDisposeable
and could be left off.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.