组件类 [英] Component class

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

问题描述

有时,我们在应用程序中使用组件类.为什么使用此组件类?有什么好处吗?

当我向应用程序添加组件类时,我只能在它的工具箱上找到两个链接,然后单击此处以切换代码视图,当我选择任何工具显示在组件表上时,便可以运行该文件,但是我添加了这些工具我的组件设计器在我的输出中不可见.

Some times we use component class in our applications. Why this component class is used? Does it have any advantages?

When I added component class to my application,I could find only two links over it toolbox and click here to switch code view, when I select any tool it is displayed on my component sheet and I could run this file but the tools i added on my component designer is not visible in my output.

推荐答案

我不知道您问题的最后一段是什么意思,但是据我所知,组件类使您可以创建一个对象,该对象可以拖到VS设计图面上,因此可以成为组件托盘的一部分.

优点在于,用于创建组件的代码在designer.cs文件中处理,并且在编写代码时无需您考虑,除了设置对象的属性等之外.

一个示例可以是SerialPort对象.您可以将其拖放到设计器图面上,然后SerialPort comms = new SerialPort();发生在设计器中,而您不必担心在代码中显式地执行它.

组件的主要优点(据我所知)是可以进行控件之类的操作,而无需手动设置位置属性等即可添加和放置在窗体上.

希望这可以澄清一下:)

Dave
I don''t know what the last parapgraph of your question means, but as far as I know, the component class allows you to create an object that can be dragged onto the VS design surface and therefore be part of your component tray.

The advantages are that the code to create the component are handled in the designer.cs file and do not have to be considered by you when you are writting code except for setting up the object''s properties etc.

An example could be a SerialPort object. You can drag and drop it onto the designer surface and then the SerialPort comms = new SerialPort(); happens in designer and you don''t have to worry about explicitly doing it in code.

The main advantage for components (as far as I know) is when you get to things like Controls that can be added and placed on the form without having to set up location properties manually, etc.

Hope this gives some clarification :)

Dave


Component派生的类可以在设计模式下用于设置属性,挂接事件处理程序等,即使它没有可见性,除非您自己实现它的这一面但是使用Control作为基础会更容易.
这听起来似乎没有什么优势,但在当今的拖放编程世界中,这是有道理的.
A class deriving from Component can be used in design mode for setting properties, hooking up event handlers etc even though it will have no visibility, unless you implement that side of it yourself but then it''d be easier to use Control as a base.
This doesn''t sound like much of an advantage but it today''s drag and drop programming world it makes sense.


这篇关于组件类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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