Visual C# 中用户控件的用途是什么? [英] What are the purpose of User Controls in Visual C#?

查看:41
本文介绍了Visual C# 中用户控件的用途是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

用户控制——它们有特殊用途吗?

User Controls -- Do they serve a special purpose?

据我所知,它们与表单没有什么不同 - 它们具有相同的工具箱和功能.

As far as I can tell they are no different to forms - they have the same toolbox and features.

是否在某些时候适合使用过度表格?了解它们的用途会很有趣.

Are there certain times when they are appropriate to use over forms? It would be interesting to understand what they are good for.

推荐答案

您可以使用它们以可重复使用的方式将一组控件和行为组合在一起.除非将控件添加到某个表单中,否则您无法在屏幕上显示该控件.

You use them to group a set of controls and behaviors together in a re-usable way. You can't show a control on the screen unless it's added to a form somewhere.

一个很好的例子是文本框.在文本框旁边有一个标签是很常见的.您可以构建一个用户控件来简化此操作.只需在控件上放置一个标签和一个文本框,公开您想要的任何属性,在您的工具箱中设置新控件,现在您只需将此控件放置在您的表单上,而无需在表单上排列标签和工具箱分开.

One good example is a textbox. It's very common to have a label next to your textboxes. You can build a user control to make this easier. Just drop a label and a textbox on the control, expose whatever your properties you want, setup the new control in your toolbox, and now you can just drop this control on your form instead of needing to arrange a label and a toolbox on the form separately.

您可以将它们视为记住"您在其上放置的控件的面板.还有一件更重要的事.您也可以将代码放入这些控件中,并使用它们将特殊行为构建到您的自定义控件中.

You could kind of think of them as a panel which "remembers" what controls you put on it. And there's one more important piece. You can put code in these controls as well, and use that to also build special behaviors into your custom controls.

这篇关于Visual C# 中用户控件的用途是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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