[英]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.