原文: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即可。

WPF中嵌入WinForm中的webbrowser控件的更多相关文章

  1. Visual C#中的winform/webform/asp.net控件命名规范

                                                                            1.控件命名规范 类型 前缀 示例 AdRotator ...

  2. WinForm webbrowser控件的使用

    webbrowser是一个比较实用的工具,主要用于在winform窗体中嵌入浏览器,达到winform与webform互操作的目的. 先上一个demo,看一下能实现什么效果. private void ...

  3. C# WebBrowser控件使用整理

    一.简介 WebBrowser 控件为 WebBrowser ActiveX 控件提供了托管包装. 托管包装使您可以在 Windows 窗体客户端应用程序中显示网页. 使用WebBrowser 控件, ...

  4. WPF中不规则窗体与WebBrowser控件的兼容问题解决办法

    原文:WPF中不规则窗体与WebBrowser控件的兼容问题解决办法 引言 这几天受委托开发一个网络电视项目,要求初步先使用内嵌网页形式实现视频播放和选单,以后再考虑将网页中的所有功能整合进桌面程序. ...

  5. WPF中禁止WebBrowser控件打开新窗口

    一.针对纯WPF的WebBrowser控件: <summary> Suppress Script Errors In WPF WebBrowser </summary> pub ...

  6. 在WPF的WebBrowser控件中屏蔽脚本错误的提示

    在WPF中使用WebBrowser控件显示网页时,经常会报脚本错误的提示,如何屏蔽掉这些错误提示呢.方法是定义如下方法: public void SuppressScriptErrors(WebBro ...

  7. Winform中修改WebBrowser控件User-Agent的方法(已经测试成功)

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.W ...

  8. 在WPF的WebBrowser控件中抑制脚本错误

    原文:在WPF的WebBrowser控件中抑制脚本错误 今天用WPF的WebBrowser控件的时候,发现其竟然没有ScriptErrorsSuppressed属性,导致其到处乱弹脚本错误的对话框,在 ...

  9. winform中WebBrowser控件执行脚本

    在实际应用中我们可能需要WebBrowser控件主动执行我们需要的脚本,执行脚本现在有两种方法. 1.WebBrowser控件加载脚本,简单方便,适用于简短的脚本,无法执行复杂操作. webBrows ...

随机推荐

  1. 系统如何端子app弄root才干

    最近由于调试USB OTG怪东西.这导致USB端口被占用,这项.虽然我是project版本号,但不能运行adb shell,这是不可能的debug该. 所以,我现在是一个系统终端apk,规划 http ...

  2. Android应用启动还有一个应用

    已知包名和应用入口Activity 包名:org.ww 应用入口:Activity:org.ww.TestActivity Intent intent = new Intent(); intent.s ...

  3. ZOJ 3795 Grouping(Tarjan收缩点+DAG)

    Suppose there are N people in ZJU, whose ages are unknown. We have some messages about them. The i-t ...

  4. Nginx + IIS 配置,实现负载均衡

    当你的Web应用程序访问量大的时候,一台服务器可能会因为压力过大而无法处理所有的请求.此时,可以增加服务器,采用负载均衡来分担所有的请求.关于Nginx的作用,自行百度了解.总之,在Windows平台 ...

  5. TFS:TF30042 数据库已满 处理方法

    原文:TFS:TF30042 数据库已满 处理方法 今天早上,公司打来电话,说TFS(Team Foundation Server)微软源代码管理软件签入不了,报错:TF30042 数据库已满. 经过 ...

  6. c#委托实例化和调用语句

    系统訪问数据或调用方法有两种操作方式:一种是通过名称訪问或调用,还有一种是通过所在的内存地址来訪问调用.为了系统的安全与稳定,NET Framework的CLR库不同意程序通过指针来直接操作内存中数据 ...

  7. 依据Uri获得sd卡图片

    <pre name="code" class="java">String mBigImage = URLEncoder.encode(mImageU ...

  8. Linux下一个CD翻录 创CUE 压缩flac攻略

    于Windows我们通常使用较低EAC翻录压缩发生器CUE找工作的步骤,但在Linux在稍微有点麻烦.每一步,我们需要自己做.经过我的反复尝试寻找和总结了相当不错的方法,使用软件和步骤如下面的. 使用 ...

  9. 读改善c#代码157个建议:建议1~3

    目录: 建议一:正确操作字符串 建议二:使用默认转型方法 建议三:区别对待强制转型和as 建议一.正确操作字符串 1.确保尽量少的装箱 static void Main(string[] args) ...

  10. Oracle解锁的相关操作(转)

    当某个数据库用户在数据库中插入.更新.删除一个表的数据,或者增加一个表的主键时或者表的索引时,常常会出现ora-00054:resource busy and acquire with nowait ...