65.9K
CodeProject is changing. Read more.
Home

Using late binding to ActiveX controls in C#

starIconemptyStarIconemptyStarIconemptyStarIconemptyStarIcon

1.00/5 (5 votes)

Feb 13, 2007

CPOL
viewsIcon

26156

Using ActiveX controls in Windows Forms applications using C#. NET.

Introduction

Recently, I has to use an ActiveX object (ThumbCtl class) and I had some problems with using an ActiveX control on a Windows Form.

Solution

You must consider that ActiveX controls can't be put directly on a Windows Form. For that, you have to do these steps:

  1. Generate wrapper assemblies for your ActiveX object. You can do this using the aximp.exe tool, e.g., aximp.exe c:\windows\system32\WEBVW.dll. Now you have generated two files: AxWEBVWLib.dll and WEBVWLib.dll.
  2. Add a reference to AxWEBVWLib.dll to your project.
  3. Now use your control like this:
  4. // Create new wrapper instance
    AxWEBVWLib.AxThumbCtl axctl = new AxWEBVWLib.AxThumbCtl();
    // Add object to specific window (control)
    mypanel.Controls.Add(axctl);
    // Set dock style
    axctl.Dock = DockStyle.Fill;
    // use OCX control methods (here we create thumbnail for our jpg file)
    axctl.displayFile(@"c:\temp\graphics.jpg");