【发布时间】:2010-06-20 23:09:16
【问题描述】:
我很困惑,谁能帮帮我?
编辑
我的问题是我在 Delphi 中创建了一个 ActiveX 控件,但我无法让它在 WPF 领域中很好地发挥作用。我查看了相关的 MSDN 页面,看起来它应该可以工作,所以我一开始创建 ActiveX 控件的方式可能出错了。
【问题讨论】:
我很困惑,谁能帮帮我?
编辑
我的问题是我在 Delphi 中创建了一个 ActiveX 控件,但我无法让它在 WPF 领域中很好地发挥作用。我查看了相关的 MSDN 页面,看起来它应该可以工作,所以我一开始创建 ActiveX 控件的方式可能出错了。
【问题讨论】:
它们是生活在完全不同的世界的控件。
System.Windows.Controls.Control 是一个WPF 控件。
System.Windows.Forms.Control 是一个WinForms 控件。
选择很简单。如果您正在开发 WinForms 应用程序 - 使用 WinForms 控件。同样,如果您正在编写 WPF 应用程序 - 使用 WPF 控件。
至于在 WPF 和 WinForms 之间进行选择 - this question 可能会有所帮助。
【讨论】:
查看这两个类的官方文档
这是 System.Windows.Controls.control 类的类签名
public class Control : FrameworkElement
这是 System.Windows.Forms.Control 类的类签名
public class Control : Component, IOleControl,
IOleObject, IOleInPlaceObject, IOleInPlaceActiveObject, IOleWindow, IViewObject,
IViewObject2, IPersist, IPersistStreamInit, IPersistPropertyBag, IPersistStorage,
IQuickActivate, ISupportOleDropSource, IDropTarget, ISynchronizeInvoke, IWin32Window,
IArrangedElement, IBindableComponent, IComponent, IDisposable
【讨论】:
System.Windows.Controls.Control 用于 WPF 应用程序
System.Windows.Forms.Control 适用于 Winforms 应用程序。
【讨论】:
System.Windows.Forms.Control
定义控件的基类,控件是具有可视化表示的组件。
System.Windows.Controls.Control
表示使用 ControlTemplate 定义其外观的用户界面 (UI) 元素的基类。
【讨论】:
什么是 Windows Presentation Foundation 和 Windows 窗体?
您应该能够从命名空间中确定一个是 WPF 的 base 控件类(所有 WPF 都使用 .Windows 命名),另一个是 Windows 窗体。
你能澄清一下你到底发现了什么令人困惑吗?我会更新我的答案。
HTH,
有用的链接
- Windows Forms Controls and Equivalent WPF Controls
- System.Windows.Forms
- System.Windows.Controls
【讨论】:
我认为有许多不同之处,但首先想到的是System.Windows.Controls.Control 使用模板来定义控件的视觉方面,没有模板它根本没有视觉方面。换句话说,如果不定义该模板,您就无法将其集中在您的应用程序中以使其可见或显示它,因为它实际上没有可视化定义。
另一方面,您有一个System.Windows.Forms.Control,它允许您创建一个继承自 UserControl、控件类或其他 Windows 控件的控件。如果您没有为控件指定新的视觉设置,它将根据您继承的父控件的设置显示。
因此,使用System.Windows.Controls.Control,您可以获得更多的灵活性,因为额外工作的成本,而使用System.Windows.Forms.Control,您可以从现有控件继承,节省时间,但灵活性较低。
【讨论】: