C#中的UserControl与CustomControl [英] UserControl vs CustomControl in C#

查看:335
本文介绍了C#中的UserControl与CustomControl的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用WindowsForm的C#中的UserControl和CustomControl有什么区别?

What is the difference between UserControl and CustomControl in C# using WindowsForm?

推荐答案

两个窗口都有自定义控件和用户控件应用程序和Web应用程序。 Windows应用程序控件的扩展名为.cs。

There are custom and user controls for both windows applications and web applications. The windows application controls have a .cs extenstion.

从一般意义上讲,用户控件更易于创建。您可以将现有控件(如文本框,标签等)拖到表单上。自定义控件通常较难创建(耗时),但具有更大的灵活性,可定制性和集成性。

In a very general sense a user control is easier to create. You can drag existing controls like textboxes, labels, etc on to the form. Custom controls are generally more difficult (time consuming) to create, but offer greater flexibility, customiseability, and integration.

是这样的:

The major difference in a nutshell is this:

用户控件由现有控件组成。由于这个事实,有时也称为复合控件。一个典型的例子是登录表单。表格和所有逻辑都包含在此可重用用户控件中。

A user control is made up of existing controls. It is also sometimes referred to as a composite control because of this fact. A typical example is a login form. The form and all of the logic is contained within this 'reuseable' user control.

自定义控件是您创建的控件。在Windows窗体中,这意味着如上面的示例中那样重写OnPaint方法。自定义控件的设计时间支持级别与用户控件不同(例如,拖放现有控件等)。自定义控件通常被认为是可以添加到Visual Studio工具箱中的可重用组件,因此它们通常不特定于您的业务或代码。

A custom control is a control that you create. In windows forms this means overriding the OnPaint method as in your example above. Custom controls do not have the same level of design time support as user controls do (ie dragging and dropping existing controls, etc). Custom controls are generally thought of as reuseable components that can be added to the toolbox of visual studio, so they typically are not specific to your business or code.

链接,其中包含一些代码示例,其形式不同: http://samples.gotdotnet .com / quickstart / winforms / doc / WinFormsCreatingControls.aspx

Here is a link that goes into the different forms with some code examples: http://samples.gotdotnet.com/quickstart/winforms/doc/WinFormsCreatingControls.aspx

这篇关于C#中的UserControl与CustomControl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆