海康visionmaster-在WPF中使用Winform控件的方法

描述

环境:VM4.0.0 + VS2013及以上

现象:在算子SDK开发过程中,用户如何使用封装好的Winform模板匹配等控件?

解答

  1. 首先添加对如下两个dll文件的引用:WindowsFormsIntegration.dll,System.Windows.Forms.dll。
    在这里插入图片描述
  2. 在要使用WinForm控件的WPF窗体的XAML文件中添加引用。示例代码如下:

C#

xmlns:wf=“clr-namespace:System.Windows.Forms;assembly=System.Windows. Forms”
xmlns:wfi=“clr-namespace:System.Windows.Forms.Integration;assembly= WindowsFormsIntegration”

  1. 在WPF的容器控件内如StackPanel内首先要添加WinForm控件的宿主容器,用于衔接WPF和WinForm。示例代码如下:

C# XAML

"
  1. 在代码中定义UserControl1 user= new UserControl1 (); 这里不要忘记添加引用。UserControl1 是自定义的Winform用户控件,用于存放控件。然后再将控件放入WindowsFormsHost 中,示例代码如下:

C# .CS

UserControl1 user= new UserControl1 ();
this.host.Ch

posted @   视觉人机器视觉  阅读(154)  评论(0编辑  收藏  举报  
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 张高兴的大模型开发实战:(一)使用 Selenium 进行网页爬虫
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
点击右上角即可分享
微信分享提示