我为什么要插入来自设计师的非UI组件Windows.Forms的? [英] Why should I insert a non-UI Windows.Forms component from the designer?

查看:159
本文介绍了我为什么要插入来自设计师的非UI组件Windows.Forms的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C#(和Visual Basic),你可以从直接添加一些非UI组件(那些没有从 System.Windows.Forms.Control的继承)窗体设计器。这些组件的例子是 System.Windows.Forms.FolderBrowserDialog System.Windows.Forms.Timer

In C# (and Visual Basic) you can add several non-UI components (those that don't inherit from System.Windows.Forms.Control) directly from the form designer. Examples of those components are System.Windows.Forms.FolderBrowserDialog and System.Windows.Forms.Timer.

但是,什么是从加入非UI的利益与UI设计师控件,而不是直接从代码中实例化他们? ?还有背后的理由。

But what's the benefit from adding non-UI controls with the UI designer instead of instancing them directly from code? There's a rationale behind that?

推荐答案

我想使用非UI组件的设计,至少有以下好处:

I think using non-UI components in designer at least has these benefits:

设计时支持

对,你在Windows窗体有最强大的东西是用设计师安装组件的能力。结果
即使定时不是一个UI组件,但您可以设置它的属性,如在设计的时间间隔。这适用于许多其他组件,如的BindingSource ErrorProvider ,...,您可以用非常友好的属性网格和类型。编辑和类型转换器配置在设计时的属性。

One of most powerful things that you have in windows forms is the ability to use designer to setup Components.
Even though Timer is not a UI component, but you can set its properties like interval at design time. This applies to many other components like BindingSource, ErrorProvider, ... that you can use very friendly property grid and type editors and type converters to configure properties at design time.


  • 当你想配置其他控件相关的性能;例如添加的BindingSource 来的设计师,它使数据绑定非常简单。

  • 当你需要使用扩展器提供商,如 HelpProvider 工具提示,因为它们与其他控件,这很容易在设计模式对其进行配置。

  • 当你需要配置如数据源数据成员属性,它是非常友好的使用设计师并用巨大的属性网格的功能。

  • 将组件添加为一流水平的领域,你可以使用deigner予以公布。

  • 当你需要使用表格本地化功能为组件,它利用设计师的完全可用。

  • 当你需要简单地添加或移除事件处理程序,你可以使用属性网格做到这一点。

  • When you want to configure dependent properties for other controls; for example by adding BindingSource to designer, it makes data binding very easy.
  • When you need to use extender providers like HelpProvider and Tooltip, since they are related to other controls, it is very easy to configure them at design mode.
  • When you need to configure properties like DataSource and DataMember, it is very friendly to use designer and use great property grid features.
  • Components will add as class level fields, and you can make them public using deigner.
  • When you need to use Localizable feature of Form for your components, it's completely available using designer.
  • When you need to simply add or remove event handlers you can do it using property grid.

标准代码

如果您在设计器生成的代码,你会看到我们来看一看:

If you take a look at designer generated code you will see:


  • 为组件生成的代码支持 ISupportInitialize接口使用了 BeginInit在 EndInit在

  • 对于组件生成的代码,通过 this.components 来构造函数,然后使用它时,处置

  • Generated code for components that supports ISupportInitialize uses their BeginInit and EndInit
  • Generated code for components, pass this.components to constructor and then use it when Dispose

如果你不需要的设计时支持你写的组件标准的代码,所以这是完全可以使用代码中的主题。

If you don't need design-time support and you write standard code for components, so it's completely OK to use theme in code.

这篇关于我为什么要插入来自设计师的非UI组件Windows.Forms的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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