何时添加组件类与用户控件?

When to add a Component Class vs User Control?(何时添加组件类与用户控件?)

本文介绍了何时添加组件类与用户控件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个大致的想法,有一些明显的案例,但对我来说也有一些灰色地带 - 什么时候最好使用从组件扩展,什么时候最好创建用户控件?这与我要解决的特定工作问题有关,但其细节并不重要——对这个问题的一般回答对我来说就足够了.

I have a general idea, and there are some obvious cases, but there are also some gray areas for me - when is it best to use to extend from a component and when is it best to create a user control? This pertains to a specific work problem I am trying to solve, but the specifics of that are not important - a general answer to this question is enough for me.

推荐答案

在 WPF 和 Windows 窗体中,主要区别在于 UserControl 是控件的集合 - 一个可重用的单个对象组合"自多个控件本身.

In WPF and Windows Forms, both, the main difference is that a UserControl is meant to be a collection of controls - a reusable, single object "composed" from multiple controls themselves.

如果您正在制作具有新行为的单个原始控件,而不是制作由较小控件组成的控件",那么您将实施 Component/CustomControl/Control 而不是 UserControl.组件通常是一种非可视化的行为,其中一个CustomControl/Control通常是一个可视化的控件.

You'd impelemnt a Component/CustomControl/Control instead of a UserControl if you are making a single, primitive control with new behavior, instead of making a "control" that's composed of smaller controls. Component usually is a non-visual behavior, where a CustomControl/Control is usually for a visual control.

这篇关于何时添加组件类与用户控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:何时添加组件类与用户控件?

基础教程推荐