什么是用户控件,自定义控件和组件之间的区别? [英] What is the difference between User Control, Custom Control and Component?

查看:306
本文介绍了什么是用户控件,自定义控件和组件之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是三个不同的东西,你可以添加到一个项目,我不是很肯定,如果我理解上的差异。他们似乎都比如说在部件工具箱中显示了一个表格时。什么是他们每个人的一些常见的使用场景?有什么区别?

These are three different things you can add to a project and I am not quite sure if I understand the difference. They all seem to for example show up in the component toolbox when working with a Form. What are some common usage scenarios for each of them? What is the difference?

推荐答案

用户控制之间的主要区别,自定义控件和组件的是,他们从不同的层面的继承树继承:

The main difference between User Control, Custom Control and Component is that they inherit from different levels in the inheritance tree:

MyComponent
   |-> Component

MyCustomControl
   |-> Control
          |-> Component

MyUserControl
   |-> ContainerControl
          |-> ScrollableControl
                 |-> Control
                        |-> Component

所以,总之你获得不同金额的pre-连接功能不同的选项。

So, in short you get a different amount of pre-wired functionality with the different options.

当您需要使用不同的选项? (这些想法和意见,而不是真理)

When would you use the different options? (these are thoughts and opinions, not truths)


  • 创建一个组件如果您想提供的功能,而用户界面(如定时器组件,数据源,...)

  • 创建一个自定义控制如果你想,你有充分的在其外观的控制,然后你不想要的不必要的功能的行李一个组成部分。典型案例是具有有限功能的简单控件(如按钮)

  • 创建一个用户控制如果您打算为结合现有的控制成可重用的构建块(如两个列表的按钮,你可以在列表之间移动项目)。

  • Create a component if you want to provide functionality without UI (such as Timer components, data sources, ...)
  • Create a custom control if you want to make a component where you have full control over its visual appearance, and you don't want any baggage of unnecessary functionality. Typical cases would be simple controls with limited functionality (such as a button)
  • Create a user control if you are going to combine existing controls into reusable building blocks (such as two lists with buttons where you can move items between the lists).

这篇关于什么是用户控件,自定义控件和组件之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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