Control vs UserControl in WinForms?(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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:WinForms中的Control vs UserControl?
基础教程推荐
- 如果有人提交恶意软件Nuget包怎么办? 2022-01-01
- 我应该在后面的代码中直接使用 Linq To SQL 还是使 2022-01-01
- 如何使用 .Net 检查 Active Directory 服务器是否已启动并正在运行? 2022-01-01
- 禁止输入少量字符,例如'<'、'&a 2022-01-01
- Azure Functions:CosmosDBTrigger 未在 Visual Studio 中触发 2022-01-01
- Moq It.Is<>不匹配 2022-01-01
- C# 从 List<List<int>> 中删除重 2022-01-01
- .NET SerialPort DataReceived 事件未触发 2022-01-01
- 当值可以是对象或空数组时反序列化 JSON 2022-01-01
- WPF 模态进度窗口 2022-01-01
