zoukankan      html  css  js  c++  java
  • wpf使用activex YI

    客户要求在wpf编辑个office,莫名。。。

    用过点聚的weboffice。

    嵌入个浏览,犹豫了下,还是封装个dll吧。

    安装注册你要用的ocx

    1.新建个”windows窗体组件库“工程

    2、点击工具箱邮件==》选择项==》com组件找到他

    3、把这个东西拖入到usercontrol的界面里面,你会发现该工程引用会多2个dll

    4、生成工程。ok,你发现,里面有2个莫名的dll

    到目前你dll算引入完成。

    1、新建个wpf工程

    2、建个userctrol

    引用上面生成的dll

    
    //引入
    using System.Windows.Controls;
    using System.Windows.Forms.Integration;
    
    //new一个备用
    
    private AxWEBOFFICELib.AxWebOffice _axWebOffice;
    
    //new一个容器备用。
    
    private System.Windows.Forms.Integration.WindowsFormsHost _winHost;
    
    
    //在构造函数里面初始化下
    
    public OfficeAtiveX()
    {
    InitializeComponent();
    _winHost = new WindowsFormsHost();
    _axWebOffice = new AxWebOffice();
    if (_winHost.Child != null)
    {
    _winHost.Child.Dispose();
    _winHost.Child = null;
    }
    
    _winHost.Child = _axWebOffice;
    _axWebOffice.BeginInit();//必须
    this.uoxcObox.Children.Add(_winHost);
    _axWebOffice.EndInit();//必须
    
    _axWebOffice.NotifyWordEvent += new _DWebOfficeEvents_NotifyWordEventEventHandler(_axWebOffice_NotifyWordEvent);
    
    
    }
    
    
    
    //主意哦,许多ocx需要销毁。。。请调用它的close方法,还有把_winHost 弄掉



    下面么编译,把这个usercontrol拖入到你的需要的地方就ok,再次强调销毁,特别是视频控件,注意在可见或者关闭的时候调用对应的方法

  • 相关阅读:
    javascript 笔记
    i18n,国际化翻译,excel与js互转
    nginx 一个端口布署多个单页应用(history路由模式)。
    html, js,css应用文件路径规则
    vue响应式原理,去掉优化,只看核心
    js 大量数据优化,通用方法
    nginx 常用的location rewrite proxy_pass
    javascript,排列组合
    zk分布式任务管理
    springboot+mybatis+dubbo+aop日志终结篇
  • 原文地址:https://www.cnblogs.com/loswing/p/2737842.html
Copyright © 2011-2022 走看看