在WPF中托管ActiveX控件 [英] Hosting ActiveX control in WPF

查看:78
本文介绍了在WPF中托管ActiveX控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ActiveX控件(用Delphi编写),我想将其托管在WPF应用程序中.当我尝试将其加载到工具箱中以在设计时将其添加到XAML时,它没有显示在可用控件列表中.有谁知道该列表的过滤器是什么,为什么我看不到要添加该列表的控件?

I have an ActiveX control (written in Delphi) which I want to host in a WPF application. When I try to load it into the toolbox to add it to the XAML at design time, it is not shown in the list of available controls. Does anyone know what filters this list and why I can't see the control to add it?

修改

这就是我要去的地方-host.Child = (ax);语句遇到错误(无法将类型'DemoFrameControl.DemoFrameCtrl'隐式转换为'System.Windows.Forms.Control'),希望这有助于阐明我的问题

This is where I get to - the host.Child = (ax); statement gets an error (Cannot implicitly convert type 'DemoFrameControl.DemoFrameCtrl' to 'System.Windows.Forms.Control'), hope this helps clarify my problem

    private void WindowLoaded(object sender, RoutedEventArgs e)
    {
        // Create the interop host control.
        System.Windows.Forms.Integration.WindowsFormsHost host =
            new System.Windows.Forms.Integration.WindowsFormsHost();

        // Create the ActiveX control.
        DemoFrameControl.DemoFrameCtrl ax = new DemoFrameControl.DemoFrameCtrl();

        // Assign the ActiveX control as the host control's child.
        host.Child = (ax);

        // Add the interop host control to the Grid
        // control's collection of child controls.
        this.grid1.Children.Add(host);

        // Play a .wav file with the ActiveX control.
        //axWmp.URL = @"C:\WINDOWS\Media\Windows XP Startup.wav";
    }

谢谢

推荐答案

签出演练:在WPF中托管ActiveX控件.

更新:

DemoFrameCtrl的定义方式是什么?就像错误所说的一样,它必须是System.Windows.Forms.Control的子类才能使用WindowsFormsHost. ActiveX控件包装程序将继承 AxHost Control继承的>.我认为,如果您添加对ActiveX库的引用,Visual Studio将生成包装器.如果没有,您可以尝试使用 Aximp.exe(Windows窗体ActiveX控件导入器).

How is DemoFrameCtrl defined? Like the error says, it needs to be a subclass of System.Windows.Forms.Control to use WindowsFormsHost. An ActiveX control wrapper will inherit from AxHost which inherits from Control. I think Visual Studio will generate the wrapper if you add a reference to the ActiveX library. If not, you can try using Aximp.exe (Windows Forms ActiveX Control Importer).

这篇关于在WPF中托管ActiveX控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆