C#利用AxImp工具在WPF中使用OCX控件

一、注册OCX并利用工具生成dll

@echo off
color a
::Failed
REGSVR32 /S /I "MSCOMCTL.OCX"
if exist %windir%\SysWOW64 (
.\AxImp.exe "C:\Windows\SysWOW64\MSCOMCTL.ocx" /out:.\MSCOMCTL64.dll
) else (
.\AxImp.exe "C:\Windows\System32\MSCOMCTL.ocx" /out:.\MSCOMCTL32.dll
)

pause

二、添加引用(OCX生成的dll)并编码使用

项目引用:WindowsFormsIntegration.dll,System.Windows.Forms.dll

xaml代码使用
<Window x:Class="wpf_ocx2dll.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        添加命名空间
        xmlns:ms="clr-namespace:MSComctlLib;assembly=MSComctlLib"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <WindowsFormsHost x:Name="host">
            <ElementHost>
                <!--<ms:Button Caption="test" />-->
            </ElementHost>
        </WindowsFormsHost>
    </Grid>
</Window>

或cs代码使用

 MSComctlLib.IButton btn = new MSComctlLib.Button();
        public MainWindow()
        {
            InitializeComponent();
            try
            {
                ((System.ComponentModel.ISupportInitialize)btn).BeginInit();
                //host.Child =btn;
                ((System.ComponentModel.ISupportInitialize)btn).EndInit();

            }
            catch (Exception ex)
            {
            }
        }

  

所用工具:http://pan.baidu.com/s/1i4AIBxr

时间: 2024-08-25 04:29:58

C#利用AxImp工具在WPF中使用OCX控件的相关文章

WPF 中动态改变控件模板

在某些项目中,可能需要动态的改变控件的模板,例如软件中可以选择不同的主题,在不同的主题下软件界面.控件的样式都会有所不同,这时即可通过改变控件模板的方式实现期望的功能. 基本方法是当用户点击切换主题按钮是加载新的资源字典,并使用新加载的资源字典替代当前的资源字典这时要用到ResourceManager. 假设现有两个不同的资源字典文件Dictionary1.xaml和Dictionary2.xaml存在于Themes文件夹内: 在MainPage中使用其中一个资源字典作为默认样式文件: <Win

在WPF中使用WinForm控件方法

1.      首先添加对如下两个dll文件的引用:WindowsFormsIntegration.dll,System.Windows.Forms.dll. 2.      在要使用WinForm控件的WPF窗体的XAML文件中添加如下内容: 即: xmlns:wf="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms" xmlns:wfi ="clr-namespace:System.Windo

在WPF中调用Winform控件

最近在项目中用到了人脸识别和指纹识别,需要调用外部设备和接口,这里就用到了在WPF中调用Winform控件. 第一步,添加程序集引用.System.Windows.Forms和WindowsFormsIntegration 第二步,添加对Winform控件的引用(选中部分) 第三步,添加控件(包在WindowsFormsHost中)

WPF中的ControlTemplate(控件模板)(转)

原文地址 http://www.cnblogs.com/zhouyinhui/archive/2007/03/28/690993.html WPF中的ControlTemplate(控件模板)                                                                                                                        周银辉 WPF包含数据模板和控件模板,其中控件模板又包括Contro

Html页中使用OCX控件

原文:http://blog.csdn.net/mouse8166/article/details/5515657 最近准备开发一个b/s架构的应用程序需要用到activeX控件,web服务器尚未进入编码阶段,偶手上已有原用于vc客户端程序中的ocx控件,想测试一下此控件在普通网页上执行功能有无偏差,于是搞了个简单的html静态页面调用来测试OCX控件. 一 注册OCX控件 新建reg.txt文件 编辑RegSvr32  TestOCX.ocx  //TestOCX是控件名 保存 改名reg.b

wpf中遍历界面控件的方法

/// <summary>        /// 遍历界面中的所有控件        /// </summary>        /// <param name="uiControls"></param>        private void SetNotEditable(UIElementCollection uiControls)        {            foreach (UIElement element in u

WPF中的image控件的Source赋值

image控件的Source设置为相对路径后(Source="haha.png")运行不能显示 解决方案:当Source设置为相对路径后(Source="haha.png")Visual Studio 2013会在属性栏的Source中生成“/WpfApplication1;component/haha.png”. 不知道在其他Visual Studio中会不会这样,但是可以按照这样写就不会出现不能显示的问题. img.Source = new BitmapImag

js中调用ocx控件

项目中经常遇到js中要调用c++控件情况,通过控件来实现相关功能操作.如视频控件等 具体js中引用 object的classid 代码参考如下: <body id="body" > <div id="div" style="width:100%;height:100%;"> <object classid="clsid:61978326-6772-4595-9EC3-D23C5CD5E61F" w

在 WPF 中如何在控件上屏蔽系统默认的触摸长按事件

来源:https://stackoverflow.com/questions/5962108/disable-a-right-click-press-and-hold-in-wpf-application 在控件上可以设置一个属性: Stylus.IsPressAndHoldEnabled 设置为 False 即可屏蔽触摸长按事件的触发. 参考文档:http://msdn.microsoft.com/en-us/library/system.windows.input.stylus.ispres