如何創建沒有圖形的用戶控件?如何使用c創建沒有圖形的用戶控件#
當我使用Windows Form Control Library
創建用戶控件時,我看到了這個命令行:public partial class UserControl1: UserControl
。 我的朋友告訴我用UserControl1:Component,IDisposable
替換UserControl1: UserControl
。 我不知道Component,IDisposable
是什麼。
如何創建沒有圖形的用戶控件?如何使用c創建沒有圖形的用戶控件#
當我使用Windows Form Control Library
創建用戶控件時,我看到了這個命令行:public partial class UserControl1: UserControl
。 我的朋友告訴我用UserControl1:Component,IDisposable
替換UserControl1: UserControl
。 我不知道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
並且可以被關閉。
沒有圖形的用戶控件是不是類? – John3136
它不是一個類,它是一個UserControl,我可以將其添加到ToolBox並拖動並形成 – AJHope
@ John3136不,認爲Windows.Forms.Timer – Blorgbeard