我很困惑,有人能帮帮我吗?
编辑
我的问题是我在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之间做出选择-这个问题可能会有所帮助。
这是 System.Windows.Controls.control 类的类签名。
public class Control : FrameworkElement
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
表示用户界面(UI)元素的基类,它们使用ControlTemplate来定义其外观。
什么是 Windows Presentation Foundation 和 Windows Forms?
从命名空间中,你应该能够确定其中一个是 WPF 的 基础控件类(所有的 WPF 都使用 .Windows 命名空间),另一个则是用于 Windows Forms 的。
你可以具体说明一下你觉得什么地方令你困惑吗?我会更新我的回答。
希望对你有所帮助,
有用的链接
- 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
,您可以从现有控件继承,节省时间,但代价是灵活性较少。