2015-07-21 29 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并且可以被关闭。

相关问题