簡體   English   中英

如何使用C#創建不帶圖形的用戶控件

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

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM