Building Windows Forms Controls and Components with Rich Design-Time Features
2004-11-19 23:34
465 查看
Building Windows Forms Controls and Components with Rich Design-Time Features
Michael Weinhardt and Chris Sells
Design-time Architecture
Design mode is activated the moment a form is opened for editing. It can involve activities like resizing, setting the border style, changing the caption, and adding controls and components, which also enter design mode the moment they are dragged onto either the visual or nonvisual design surface. The nonvisual area, or component tray, hosts components. A component is a Framework class that supports the design-time experience but doesn't draw its own UI in a container-specified region. Components implement the System.ComponentModel.IComponent interface, typically by deriving from the SystemComponent.Model.Component base class. Controls, on the other hand, do draw themselves and are therefore shown in the visual area. All controls ultimately derive from the System.Windows.Forms.Control class, which in turn derives from the Component base class. In other words, a control is really a component with a UI. Both act nearly identically at design time in terms of their integration with the design host. Figure 1 shows a form in design mode acting as a design host for a number of components and controls.
While both components and controls ultimately derive from the Component base class, that's not what distinguishes a component from any other class. Instead, what makes the Component class fit into the design-time architecture is its implementation of the IComponent interface. IComponent allows components to integrate with the design-time host, providing them with design-time services.
设计时架构
一旦窗体被打开编辑,设计模式就被激活了。它可以接受很多行为,例如,调整大小、设置边框风格,改变标题,同时也包括添加control(控件)和Component(组件),当它们被拖拽到可视或非可视区域时,也进入了设计模式。非可视区域,或者称为组件托盘,用来存放组件。组件是一个Framework类,它支持设计时体验,但是它不在container(容器)指定的区域绘制自己的UI(用户界面)。组件实现System.ComponentModel.IComponent接口,更典型的,它继承自基类System.ComponentModel.Component。另一方面,控件却(do)绘制自己,因此它们可以显示在可视区域。所有控件最终都继承自System.Windows.Forms.Control类,而后者又继承自Component基类。换句话说,控件实际上是带有UI的组件。在设计时期间,二者与设计宿主结合的方式几乎完全一致。图1显示了一个在设计模式下做为许多组件和控件的设计宿主的窗体。
既然组件和控件都最终继承自Component基类,因此组件与其它类没有什么区别。Instead,使Component类适合设计时架构的是它对IComponent接口的实现。IComponent允许组件与设计时宿主结合,并为它们提供设计时服务。
对IContainer接口的这一实现允许设计器宿主建立关系,从而帮助它管理放在窗体上每一个组件。
Sites
At design time, contained components can access the designer host, as well as each other, through their container. This two-way relationship is shown in Figure 2. You can also see that the fundamental relationship between the designer host and its components is established with an implementation of the System.ComponentModel.ISite interface:
在设计时,被包含的组件和设计器宿主可以通过它们之间的容器互相访问。这一双向的关系显示在图2中。可以看到,设计器宿主和其组件的基础关系是通过实现一个System.ComponentModel.ISite接口建立的:
IDesignerHost designerHost = this.Container as
IDesignerHost;
In Visual Studio .NET, the designer has its own implementation of the IDesignerHost interface, but to fit into other designer hosts, it's best for a component to rely only on the interface and not any specific implementation.
在Visual Studio .NET中,设计器有它自己对IDesignerHost接口的实现,不过为了适应其它的设计器宿主,组件最好只依赖接口而不应依赖于其特定的实现。
Michael Weinhardt and Chris Sells
Design-time Architecture
Design mode is activated the moment a form is opened for editing. It can involve activities like resizing, setting the border style, changing the caption, and adding controls and components, which also enter design mode the moment they are dragged onto either the visual or nonvisual design surface. The nonvisual area, or component tray, hosts components. A component is a Framework class that supports the design-time experience but doesn't draw its own UI in a container-specified region. Components implement the System.ComponentModel.IComponent interface, typically by deriving from the SystemComponent.Model.Component base class. Controls, on the other hand, do draw themselves and are therefore shown in the visual area. All controls ultimately derive from the System.Windows.Forms.Control class, which in turn derives from the Component base class. In other words, a control is really a component with a UI. Both act nearly identically at design time in terms of their integration with the design host. Figure 1 shows a form in design mode acting as a design host for a number of components and controls.
While both components and controls ultimately derive from the Component base class, that's not what distinguishes a component from any other class. Instead, what makes the Component class fit into the design-time architecture is its implementation of the IComponent interface. IComponent allows components to integrate with the design-time host, providing them with design-time services.
设计时架构
一旦窗体被打开编辑,设计模式就被激活了。它可以接受很多行为,例如,调整大小、设置边框风格,改变标题,同时也包括添加control(控件)和Component(组件),当它们被拖拽到可视或非可视区域时,也进入了设计模式。非可视区域,或者称为组件托盘,用来存放组件。组件是一个Framework类,它支持设计时体验,但是它不在container(容器)指定的区域绘制自己的UI(用户界面)。组件实现System.ComponentModel.IComponent接口,更典型的,它继承自基类System.ComponentModel.Component。另一方面,控件却(do)绘制自己,因此它们可以显示在可视区域。所有控件最终都继承自System.Windows.Forms.Control类,而后者又继承自Component基类。换句话说,控件实际上是带有UI的组件。在设计时期间,二者与设计宿主结合的方式几乎完全一致。图1显示了一个在设计模式下做为许多组件和控件的设计宿主的窗体。
既然组件和控件都最终继承自Component基类,因此组件与其它类没有什么区别。Instead,使Component类适合设计时架构的是它对IComponent接口的实现。IComponent允许组件与设计时宿主结合,并为它们提供设计时服务。
对IContainer接口的这一实现允许设计器宿主建立关系,从而帮助它管理放在窗体上每一个组件。
Sites
At design time, contained components can access the designer host, as well as each other, through their container. This two-way relationship is shown in Figure 2. You can also see that the fundamental relationship between the designer host and its components is established with an implementation of the System.ComponentModel.ISite interface:
在设计时,被包含的组件和设计器宿主可以通过它们之间的容器互相访问。这一双向的关系显示在图2中。可以看到,设计器宿主和其组件的基础关系是通过实现一个System.ComponentModel.ISite接口建立的:
IDesignerHost designerHost = this.Container as
IDesignerHost;
In Visual Studio .NET, the designer has its own implementation of the IDesignerHost interface, but to fit into other designer hosts, it's best for a component to rely only on the interface and not any specific implementation.
在Visual Studio .NET中,设计器有它自己对IDesignerHost接口的实现,不过为了适应其它的设计器宿主,组件最好只依赖接口而不应依赖于其特定的实现。
相关文章推荐
- CMS programmming & UI design
- Motorola V180,V501,V600,C650等在JBuilder开发环境的配置
- UI设计模式
- Context Path + servlet path + path info = request uri
- require,include,load,extend的用途和区别
- 使用Form和QueryString集合
- 配置WebLogic 8.1到jbuilderX!
- 修改图标
- J2ee学习流程[转]
- Building a Drum Machine with DirectSound.
- 00022.Problem when building openh323 on Fedora3.
- [原创]手把手配置Hibernate环境(JBuilderX版)
- 使用Quest Toad的一些心得
- 用好活动字幕标记—marquee
- ant学习指南
- 开发环境的配置
- 面试时最经常被问到的问题(Frenquently asked interview questions)(II)
- 面试时最经常被问到的问题(Frenquently asked interview questions)(I)
- MFC对话框程序中添加工具栏及工具栏上的Button响应UPDATE_COMMAND_UI消息
- 一些常见的GUI对应的程序名称整理