WinForms中的Control vs UserControl?

Control vs UserControl in WinForms?(WinForms中的Control vs UserControl?)
本文介绍了WinForms中的Control vs UserControl?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

.NET WinForms 中的 Control 和 UserControl 有什么区别?我想创建一个自定义控件,但我应该从哪个继承?我过去一直使用 Control 没有任何问题,但是创建自定义控件的推荐"方式是什么?

What is the difference between a Control and a UserControl in .NET WinForms? I want to create a custom control, but which one should I inherit from? I've always used Control in the past without any issues, but is the "recommended" way of creating a custom control?

推荐答案

这里有一篇关于这个问题的好文章.用户控件

Here is a good article about this question. user controls

总之

控件要么是继承的,要么是完全自定义的.您自己编写和处理许多事件.您甚至可以通过使用 GDI+ 来控制绘制控件的方式和时间绘图.

A Control is either inherited or completely custom. You write and handle many of the events yourself. You can even control how and when the control is drawn thru the use of GDI+ drawing.

UserControl 是一组控件,这些控件放在一起以某种方式使用.例如,您可以放置​​一个包含文本框、复选框等的 GroupBox.当您必须在多个表单或选项卡上/中放置同一组控件时,这很有用.注意:您也可以为 UserControls 编写一些自定义事件和绘图.

A UserControl is a collection of controls placed together to be used in a certain way. For example you can place a GroupBox that contains Textbox’s, Checkboxes, etc. This is useful when you have to place the same group of controls on/in multiple forms or tabs. Note: you can write some custom events and drawing for UserControls also.

这篇关于WinForms中的Control vs UserControl?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
quot;Overflowquot; compiler error with -9223372036854775808L(编译器错误-9223372036854775808L(Q;溢出Q))
Visual Studio 2010 ReportViewer Assembly References(Visual Studio 2010 ReportViewer程序集引用)
Weird behaviour when I open a reportviewer in WPF(在WPF中打开报表查看器时出现奇怪的行为)