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)
        {
        }
    }
相关推荐
余瑜鱼鱼鱼9 小时前
HTML常用标签总结
前端·html
炽烈小老头11 小时前
前端最最最基础的基础HTML基础
前端·html
怪侠_岭南一只猿14 小时前
爬虫阶段一实战练习题二:爬取当当网图书列表
css·爬虫·python·html
前端老石人16 小时前
HTML文档元素与元数据详解
前端·html
Cg1362691597420 小时前
JS函数表示
前端·html
闻哥20 小时前
深入剖析Redis数据类型与底层数据结构
java·jvm·数据结构·spring boot·redis·面试·wpf
..过云雨21 小时前
【负载均衡oj项目】01. 项目概述及准备工作
linux·c++·html·json·负载均衡
kyriewen21 小时前
Flexbox 完全指南:从此告别浮动,拥抱一维战神
前端·css·html
yatum_201421 小时前
Hadoop 三种核心运行模式(伪分布式/分布式/混合模式)全总结
hadoop·分布式·wpf
有技巧搬砖1 天前
基于WPF MVVM的流程编排状态机引擎上位机
wpf·状态机·流程步骤