打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
【转】WPF中嵌入WinForm中的webbrowser控件

【转】WPF中嵌入WinForm中的webbrowser控件

使用VS2008创建WPF应用程序,需使用webbrowser。从工具箱中添加WPF组件中的webbrowser发现其中有很多属性事件不能使用。决定还是使用WinForm中的webbrowser。要想在WPF中使用WinForm控件,查看MSDN,需经过以下步骤。
  1. 创建名为 HostingWfInWpf 的 WPF 应用程序项目。

  2. 在解决方案资源管理器中,添加一个对名为 WindowsFormsIntegration.dll 的 WindowsFormsIntegration 程序集的引用。

  3. 在解决方案资源管理器中,添加一个对名为 System.Windows.Forms.dll 的 Windows 窗体程序集的引用。

  4. 在 WPF 设计器中打开 Window1.xaml。

  5. 用以下 XAML 替换 Window1.xaml 中自动生成的 XAML。

<Window x:Class="HostingWfInWpf.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="HostingWfInWpf"
 Loaded="WindowLoaded"
    >
    <Grid Name="grid1">

    </Grid>
</Window>
6.在代码编辑器中打开 Window1.xaml.cs。
7.将 Window1.xaml.cs 中的代码替换为以下代码。

 

using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Media;
using System.Windows.Shapes;

using System.Windows.Forms;

namespace HostingWfInWpf
{  
    public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();
        }

        private void WindowLoaded(object sender, RoutedEventArgs e)
        {
            // Create the interop host control.
            System.Windows.Forms.Integration.WindowsFormsHost host =
                new System.Windows.Forms.Integration.WindowsFormsHost();

            // Create the MaskedTextBox control.
            MaskedTextBox mtbDate = new MaskedTextBox("00/00/0000");

            // Assign the MaskedTextBox control as the host control's child.
            host.Child = mtbDate;

            // Add the interop host control to the Grid
            // control's collection of child controls.
            this.grid1.Children.Add(host);
        }
    }
}

此处,将MaskedTextBox换成System.Windows.Forms.WebBrowser即可。
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
WPF学习与分享之一: WPF与WinForm比较
ckrule规则编辑器在wpf中的使用
WPF中AllowsTransparency和WebBrowser兼容性问题
C#下WPF中调用WinForm控件
WPF 浏览PDF 文件
WinForm和WPF有什么区别 • Worktile社区
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服