为什么我们创建动态控件以及主要用途是什么? [英] why we create dynamic controls and what is the main use?

查看:76
本文介绍了为什么我们创建动态控件以及主要用途是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请简要解释一下....谢谢

please explain briefly....thank you

推荐答案

我们事先不知道我们实际需要什么控件(例如)如果它们依赖于用户的选择或在外部配置,例如在数据库中。一旦动态创建,这些控件的处理方式与静态创建的控件完全相同。
We create dynamically the controls whenever we don't know in advance what controls we actually need (for instance if they depend on user's choice or are configured externally, e.g. in a database). Once dynamically created, such controls are handled exactly like the statically created ones.


主要原因是当您不知道在设计时需要多少控件时。

以下是一些黄金法则 [ ^ ]在使用动态控件时要记住。
The main reason would be when you do not know how many controls you need at design time.
Here are some Golden rules[^] to remember when working with dynamic controls.


很多原因。
正如Carlo所说,我们创建它们是因为我们在设计时不知道我们需要什么。



这可能是因为数据来自数据库,我们不知道它有多少。

或者可能是因为用户是管理员并获得更多高级控件而不是标准用户。



我们也可能在运行时创建控件,因为用户正在加载一个模板表单来描述显示内容应该看起来像在外部文件中。



但事实上,在C#中,所有控件都是动态创建的 - 即使是那些你在Winforms应用程序上固定的控件也是如此Visual Studio设计师。显示控件的代码位于myfilename.Designer.cs(适用于Winforms)文件或myfilename.aspx文件(适用于网站),如果您想了解VS是如何做的,可以自由检查。
Loads of reasons.
As Carlo has said, we create them because we don't know what we need at design time.

This may be because the data comes from a DB and we don't know how much there is of it.
Or it could be because the user is an Admin and gets more advanced controls than a standard user.

We may also create controls at run time because the user is loading a "template form" which describes what the display should look like in an external file.

But in truth, in C# all controls are created dynamically - even those you "fix in place" on a Winforms app with the Visual Studio designer. The code which displays controls is in the myfilename.Designer.cs (for Winforms) file or the myfilename.aspx file (for websites), and you can examine it freely if you want to see how VS does it.


这篇关于为什么我们创建动态控件以及主要用途是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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