C# - 什么是组件以及它通常如何使用?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/523844/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-04 06:43:04  来源:igfitidea点击:

C# - What is a component and how is it typically used?

c#components

提问by Brad

What is a component class and where would I typically use one?

什么是组件类,我通常会在哪里使用它?

When I add a new item to my project in VS.NET 2008 one of the options is to add a component. I am not even sure I understand what a component is - but I would sure like to find out a bit more about them.

当我在 VS.NET 2008 中向我的项目添加新项目时,其中一个选项是添加组件。我什至不确定我是否理解组件是什么——但我肯定想了解更多关于它们的信息。

Could somebody explain them to me or perhaps point me towards an online tutorial that would help me.

有人可以向我解释它们,或者向我指出可以帮助我的在线教程。

采纳答案by casperOne

Well, generally speaking, a component is any part of a thing. Specifically in .NET, a component is a class that implements the IComponentinterface, which indicates that a class can interact with it's logical container.

嗯,一般来说,组件是事物的任何部分。特别是在 .NET 中,组件是一个实现IComponentinterface的类,这表明一个类可以与其逻辑容器进行交互。

More often than not, you see this in the form of design support, in that classes interact with their host in the designer, but that's not a strict requirement.

通常,您会以设计支持的形式看到这一点,即类与设计器中的宿主进行交互,但这并不是严格的要求。

回答by Yordan Pavlov

If you mean a class that inherits from System.ComponentModel.Component, like for example the System.Windows.Forms.BindingSourceand strongly-typed DataSets, this will allow to drag an instance on the Visual Studio design surface (on a form in design-time) and set some properties using the property grid.

如果您的意思是从 继承的类,System.ComponentModel.Component例如System.Windows.Forms.BindingSource强类型数据集,这将允许在 Visual Studio 设计图面上(在设计时的窗体上)拖动实例并使用属性网格设置一些属性。

Once there is an instance of such component on the form it is discoverable by other components/controls. For example a BindingSourcecan be selected as a data source for a grid view or some other control.

一旦表单上存在此类组件的实例,其他组件/控件就可以发现它。例如,BindingSource可以选择 a 作为网格视图或某些其他控件的数据源。

回答by belaz

Component Classis for sharing objects between applications.

组件类用于在应用程序之间共享对象。

Typically for dropping down object like outlook email to an application.

通常用于将 Outlook 电子邮件等对象下拉到应用程序。