WPF中使用winform 控件
来源:互联网 发布:网络上bgm是什么意思 编辑:程序博客网 时间:2024/05/18 03:54
原来有一个WINFORM项目的功能模块希望集成到新的WPF项目中,怎样集成才最简单?
思路:将原来的WINFORM项目类型改为WindowsFormsControlLibrary类型就OK了。
步骤:
1、所以我们就直接建立一个WindowsFormsControlLibrary项目吧!接着我在该项目中新增Windows Form,为Form1。也就是将原来的项目类型改造为WindowsFormsControlLibrary项目。
2新建Wpf项目
(1)、添加两个引用:WindowsFormsIntegration.dll(负责整合WPF和Windows)、System.Windows.Forms.
(2)、在 XAML文件中添加两个引用(粗体部分):
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:WinFormHost="clr-namespace:System.Windows.Forms.Integration;assembly=WindowsFormsIntegration"
Title="MainWindow" Height="350" Width="525">
(3)添加HOST宿主
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:WinFormHost="clr-namespace:System.Windows.Forms.Integration;assembly=WindowsFormsIntegration"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition></ColumnDefinition>
</Grid.ColumnDefinitions>
<WindowsFormsHost Name="windowsFormsHost1" Grid.Column="0" Margin="3"></WindowsFormsHost>
</Grid>
</Window>
windowsFormsHost1 就是FORM窗体显示的宿主
(4)接着我们要在WPF项目中引用刚才WindowsFormsControlLibrary项目建出来的dll档
(5)在MainWindow.xaml.cs中添加代码
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using WindowsFormsControlLibrary1;
using System.Windows.Forms;
namespace WpfApplication1
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
private Form1 _form1 = new Form1();
public MainWindow()
{
InitializeComponent();
_form1.TopLevel = false;
_form1.FormBorderStyle = FormBorderStyle.None;
windowsFormsHost1.Child = _form1;
}
}
}
- WPF中使用winform 控件
- 在WPF中使用WinForm控件方法
- 在WPF中使用WinForm控件方法
- C# WinForm中使用WPF的控件
- WinForm中如何使用WPF中的控件
- 在WPF中使用WinForm控件方法
- WPF 使用winform控件
- C# Winform使用WPF控件
- WPF窗口中使用WinForm控件的一些限制
- WPF中使用WinForm控件预览DWG文件(学习笔记)
- 在WPF中使用WinForm或自定义控件
- 如何在WPF中调用Winform控件
- 在WinForm应用程序中嵌入WPF控件
- 在WinForm应用程序中嵌入WPF控件
- 如何在WPF中调用Winform控件
- 如何在WPF中调用Winform控件
- 在WinForm应用程序中嵌入WPF控件
- 如何在WPF中调用Winform控件
- rtmp 详细介绍
- 机器学习算法总结--SVM
- Vector、ArrayList、LinkedList、HashMap、TreeMap、HashTable 区别
- AIDL实现Android的进程通信
- Github上传代码菜鸟超详细教程
- WPF中使用winform 控件
- (转载) C语言技巧:怎样把数组作为参数传递给函数?(值传递和指针传递)
- xshell的快捷键(非常实用)
- android packagemanager
- js异步编程上手
- 训练8-HTML 更换文本的颜色
- PHP build notes - WARNING: This bison version is not supported for regeneration of the Zend/PHP pars
- B树的插入和删除
- thinkphp3.2架构及源码理解