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)
        {
        }
    }
相关推荐
Bruce_Cheung2 小时前
WPF旋转板栈设计一例
wpf·rack·tube·料盒·料管
hello_simon3 小时前
免费在线文档工具,在线PDF添加空白页,免费在任意位置插入空白页,多样化的文件处理
pdf·html·excel·pdf转html·excel转pdf格式
leslie_xin5 小时前
(原创)[开源][.Net Framework 4.5] SimpleMVVM(极简MVVM框架)更新 v1.1,增加NuGet包
c#·wpf
前端Hardy8 小时前
HTML&CSS:卡片式提交框
css·html
前端Hardy8 小时前
HTML&CSS:超有趣的登录表单
javascript·css·html
今天吃了嘛o20 小时前
vue中根据html动态渲染内容2.0
vue.js·elementui·html
低头专研21 小时前
用 HTML 网页来管理 Markdown 标题序号
前端·html·markdown·markdown标题编号
小妖66621 小时前
html 给文本两端加虚线自适应
前端·javascript·html
倒霉男孩1 天前
HTML的Canvas元素
前端·html
WEI_Gaot1 天前
HTML超链接
前端·html