Freigeben über


ActiveX controls on WinForms?

You can use Windows Forms controls in web pages – see https://msdn.microsoft.com/msdnmag/issues/02/01/UserCtrl/default.aspx

But,

We only support using Windows Forms controls in IE and in MFC7.x (see official statement of support below). We do not support using Windows Forms controls as ActiveX controls in other containers. The scenario using Windows Forms in Smart Documents is definitely not supported.

The reason for this is that (as anyone who has implemented an ActiveX control or ActiveX container knows) ActiveX is highly complex and each container is different and requires thorough testing with your control framework to make it work correctly. To date we have had the resources to test in IE and MFC but not beyond that.

Over time the story gets much better – for example the MFC team are significantly improving MFC support in Whidbey, the MMC team are working on supporting Windows Forms controls and the VSTO team are working on supporting Windows Forms controls in Office so that in the Whidbey timeframe you will be able to use Windows Forms controls in Office.

To summarize our official position on hosting Windows Forms controls:

V1.0 of Windows Forms only supports using Windows Forms controls in:

· Windows Forms

· IE 5.01 and up

Registering Windows Forms controls as ActiveX controls is not supported.

Creating Windows Forms controls using CoCreateInstance is not supported.

In V1.1 of the Framework we extended our support to include MFC 7.x and up or any container that is fully compatible with the MFC 7.x ActiveX control container.

However we do not support registration of Windows Forms controls as ActiveX controls and we do not support CoCreateInstance of Windows Forms controls. We only support managed activation of the Windows Forms controls. Once the controls are created they can be hosted in MFC just as you would any other ActiveX control.

This means that in order to use Windows Forms controls in your application you will either need to host the CLR using the unmanaged CLR hosting APIs or using Managed C++ - my recommendation would be to use Managed C++.

As well as the sample above there is an article on MSDN by Chris Sells that describes how to do this: https://msdn.microsoft.com/msdnmag/issues/03/03/WindowsForms