24.4 Using ActiveX Controls in a Windows Form

 <  Day Day Up  >  

You want to use an ActiveX control in a Windows Form application.


Technique

An ActiveX control is COM-based, which means your application makes calls into a RCW to interact with the control. The first step is to add the ActiveX control to the Windows Form designer toolbox. Right-click on the toolbox item and select the Add/Remove Items menu item. Click on the COM tab and locate the COM type library from the list of available libraries. If you don't know the name of the library, you can browse to its associated file using the Browse button.

Once you place the item onto the toolbox, you can use it as you do any other Windows Form control by dragging and dropping it and setting any necessary properties. The downloadable code for this book is available at http://www.samspublishing.com and contains a Windows Form media player, which uses the Windows Media Player ActiveX control.

Comments

Keeping with the promise of interoperability, Visual Studio .NET supports most legacy ActiveX controls. Although the term ActiveX control became somewhat synonymous with controls that run within Internet Explorer, a wide variety of applications use ActiveX controls, which serve as a successor to the OLE Custom Controls (OCXs) created in years past. If you decide to use an ActiveX control through a third party or through in-house development, you might find that it doesn't show up on the list of available COM controls within the Add/Remove form in the toolbox. COM controls, and all COM binaries for that matter, don't support XCopy deployment as .NET assemblies do. They must be registered on the system before they can be used. Registration of a COM library involves executing a special program called regsvr32.exe . This program either calls a COM DLL's DllRegisterServer method or passes the “RegServer command-line argument with an .exe or out-of-proc server. These methods in turn set the necessary Registry keys that all COM components must abide by to be actively used within Windows. Although the ATL library now takes care of this registration and unregistration mechanism, the complexity and maintenance required for COM registration is one of the driving factors behind .NET's use of attributes and XCopy deployment.

 <  Day Day Up  >  


Microsoft Visual C# .Net 2003
Microsoft Visual C *. NET 2003 development skills Daquan
ISBN: 7508427505
EAN: 2147483647
Year: 2003
Pages: 440

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net