WPF WebBrowser控件解析 HTML

WPF WebBrowser控件解析 HTML

xml 复制代码
Window里面的AllowsTransparency属性不要加
xml 复制代码
<WebBrowser x:Name="webBrowser"  />
csharp 复制代码
public void InitWeb()
{
   string htmlString = @"<html>
    <head>
        <title>this is a test</title>
        <script type ='text/javascript'>
            function Hello()
            {
                window.external.Hello('hello test'); // 传递事件
            }
        </script>
    </head>
    <body>
        <button onclick = 'Hello()'>
            hello test
        </button>
    </body>
</html> ";
            webBrowser.NavigateToString(htmlString);


            ObjectForScriptingHelper helper = new ObjectForScriptingHelper(this);
            webBrowser.ObjectForScripting = helper;
}
csharp 复制代码
    [System.Runtime.InteropServices.ComVisibleAttribute(true)]//将该类设置为com可访问
    public class ObjectForScriptingHelper
    {
        signature mainWindow;

        public ObjectForScriptingHelper(signature main) // 注意signature 要写成你自己项目中的对象名
        {
            mainWindow = main;
        }

        //这个方法就是网页上要访问的方法
        public void Hello(string cmd)
        {
        }
    }
相关推荐
我命由我123452 小时前
CSS 锚点定位 - 锚点定位引入(anchor-name、position-anchor)
开发语言·前端·javascript·css·学习·html·学习方法
高斯的手稿08013 小时前
Django里面,多个APP的url设置,每个APP单独对应HTML设置
数据库·django·html
一晌小贪欢4 小时前
【圣诞快乐 Merry Christmas】 3D 粒子变形圣诞体验
3d·html·h5·html5·圣诞网页·粒子虚幻·虚幻粒子页面
dy17174 小时前
vue左右栏布局可拖拽
前端·css·html
咬人喵喵6 小时前
告别无脑 <div>:HTML 语义化标签入门
前端·css·编辑器·html·svg
Poetinthedusk7 小时前
WPF动画制作分享
wpf·动画
OranTech8 小时前
练习02-HTML语法
html
张人玉8 小时前
WPF HTTPS 通信示例使用说明
数据库·网络协议·http·c#·wpf
张人玉8 小时前
WPF HTTPS 通信示例代码分析笔记
笔记·https·wpf
廋到被风吹走9 小时前
【Spring】ThreadLocal详解 线程隔离的魔法与陷阱
java·spring·wpf