2015-07-21 28 views
0

如何創建沒有圖形的用戶控件?如何使用c創建沒有圖形的用戶控件#

當我使用Windows Form Control Library創建用戶控件時,我看到了這個命令行:public partial class UserControl1: UserControl。 我的朋友告訴我用UserControl1:Component,IDisposable替換UserControl1: UserControl。 我不知道Component,IDisposable是什麼。

+1

沒有圖形的用戶控件是不是類? – John3136

+0

它不是一個類,它是一個UserControl,我可以將其添加到ToolBox並拖動並形成 – AJHope

+1

@ John3136不,認爲Windows.Forms.Timer – Blorgbeard

回答

2

你可以看到你的朋友都在談論,如果你看一看,你可以拖放到表單中的其他組件的一個沒有自己的界面:

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() 
    { 
     // ... 
    } 
} 

,並把它的形式:(你必須先重建,讓它在工具箱中顯示)

enter image description here

+0

您是否使用'Windows Form Control Libary'來創建myVeryOwnComponent1? – AJHope

+0

@Tuan我剛創建了一個空的WinForms項目,然後是一個空的類,並修改了類以適應我的需要。沒有特殊的庫或任何東西。 –

+0

是的,我知道,非常感謝您的幫助 – AJHope

1

你在說什麼是一個「組件」,它是從System.ComponentModel.Component派生的任何類。控制是來自類System.Windows.Forms.Control的特殊類型的組件。

如果你想讓你自己的組件從Component派生出來,這就是你的朋友用:Component,IDisposable所做的。 IDisposable部分不需要,因爲Component已經實現IDisposeable並且可以被關閉。

相關問題