因工作需要使用wpf做界面,而有个开发包依赖picturebox控件,上网研究了一下,总算弄通了。

首先在项目中添加引用System.Windows.Forms与WindowsFormsIntegration

 //在wpf主界面添加
xmlns:wfh="clr-namespace:System.Windows.Forms.Integration;assembly=WindowsFormsIntegration"
xmlns:wfc="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"
 //添加winform控件
<Grid>
<WindowsFormsHost x:Name="form1" HorizontalAlignment="Left" Height="" Margin="10,65,0,0" VerticalAlignment="Top" Width="">
<wfc:FlowLayoutPanel x:Name="flowLayoutPanel1"> </wfc:FlowLayoutPanel>
</WindowsFormsHost>
</Grid>

获取句柄

             IntPtr flpHandle = flowLayoutPanel1.Handle;//仅限主界面代码段

动态创建picturebox放到flowLayoutPanel中

 PictureBox pb = new PictureBox
{
  Width = ,
  Height = ,
  Bounds = new System.Drawing.Rectangle(, , , ),
  Name = "PictureBox" + Convert.ToString(index)
}; PictureBox temp = pb;
Control flp = Control.FromHandle(flpHandle);
//考虑动态创建可能存在跨线程访问,添加判断
if (flp.InvokeRequired)
{
  flp.Invoke(new Action(
  () => { flp.Controls.Add(temp); picHandle = temp.Handle; }
  ));
}
else
{
20   flp.Controls.Add(pb);
}

注意在非主界面程序段,不要调用界面元素,不然会报错InvalidaOperationException

wpf中插入winform控件并获取句柄的更多相关文章

  1. 在WPF中使用WinForm控件方法

    1.      首先添加对如下两个dll文件的引用:WindowsFormsIntegration.dll,System.Windows.Forms.dll. 2.      在要使用WinForm控 ...

  2. 在WPF中调用Winform控件

    最近在项目中用到了人脸识别和指纹识别,需要调用外部设备和接口,这里就用到了在WPF中调用Winform控件. 第一步,添加程序集引用.System.Windows.Forms和WindowsForms ...

  3. [转]在WPF中使用WinForm控件方法

    本文转自:http://blog.csdn.net/lianchangshuai/article/details/6415241 下面以在Wpf中添加ZedGraph(用于创建任意数据的二维线型.条型 ...

  4. 如何在WPF中调用Winform控件

    原文地址:http://hi.baidu.com/stuoopluwqbbeod/item/32ec38403da42ee2bcf45167 功能实现主要分三步:1.添加两个引用:WindowsFor ...

  5. Wpf使用Winform控件后Wpf元素被Winform控件遮盖问题的解决

    有人会说不建议Wpf中使用Winform控件,有人会说建议使用Winform控件在Wpf下的替代方案,然而在实际工作中由于项目的特殊需求,考虑到时间.成本等因素,往往难免会碰到在WPF中使用Winfr ...

  6. WPF保存包含Winform控件的XAML页面问题

    原文:WPF保存包含Winform控件的XAML页面问题 最近的工作中,用到了WPF调用Winform控件 但是在保存XAML页面的时候发现了问题,就是Winform页面黑黑的,没有任何渲染的波形曲线 ...

  7. WPF中的image控件的Source赋值

    WPF中的Image控件Source的设置 1.XAML中 简单的方式(Source="haha.png"); image控件的Source设置为相对路径后(Source=&quo ...

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

    原文地址 http://www.cnblogs.com/zhouyinhui/archive/2007/03/28/690993.html WPF中的ControlTemplate(控件模板)     ...

  9. WPF中的ControlTemplate(控件模板)

    原文:WPF中的ControlTemplate(控件模板) WPF中的ControlTemplate(控件模板)                                             ...

随机推荐

  1. 11_ for 练习 _ Math.sqrt

    <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title&g ...

  2. [LeetCode] Letter Case Permutation 字母大小写全排列

    Given a string S, we can transform every letter individually to be lowercase or uppercase to create ...

  3. 定位 position 透明度 opacity

    1.position 定位 position:fixed 固定定位 position:relative 相对定位(不指定父级元素的话相对于document) position:absolute 绝对定 ...

  4. WcPro项目(WordCount优化)

    1 基本任务:代码编写+单元测试 1.1 项目GitHub地址 https://github.com/ReWr1te/WcPro 1.2 项目PSP表格 PSP2.1 PSP阶段 预估耗时(分钟) 实 ...

  5. python 读取文本文档中的数据

    import os dir = input('Please input the file dir:')#提示输入文件路径 while not os.path.exists(dir):#判断文件是否存在 ...

  6. 安装_oracle11G_客户端_服务端_链接_oracle

    在开始之前呢,有一些注细节需要注意,oracle11G_客户端_和_服务端, 分为两种   一种是  开发者使用    一种是  BDA  自己使用(同时也需要根据自己 PC 的系统来做_win7_与 ...

  7. LeetCode 705 Design HashSet 解题报告

    题目要求 Design a HashSet without using any built-in hash table libraries. To be specific, your design s ...

  8. Mock Server 实现post方法的接口(三)

    Mock Server 实现post方法的接口(三) 1.mock server实现的接口,当request中未设置"method"时,会自动将所有method试一次,所以一定要指 ...

  9. MongoDB操作集

    官网 https://www.mongodb.com/download-center#community 基本资料: http://www.runoob.com/mongodb/mongodb-int ...

  10. gradle入门教程

    1,https://gradle.org/ 下载过后解压缩,绿色软件不需要安装. 配置系统环境:GRADLE_HOME设置为解压缩之后的地址,PATH属性追加%GRADLE_HOME%\bin; 2, ...