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)
        {
        }
    }
相关推荐
zy0101011 小时前
HTML列表,表格和表单
前端·html
我命由我123454 小时前
微信小程序 - 自定义实现分页功能
前端·微信小程序·小程序·前端框架·html·html5·js
zy0101015 小时前
HTML标签
前端·css·html
CE贝多芬5 小时前
WPF的页面设计和实用功能实现
c#·wpf
酷炫码神6 小时前
WPF布局控件
wpf
code_shenbing6 小时前
WPF 实现虚拟键盘
c#·wpf
汤永红7 小时前
在VSCode中接入deepseek
vscode·html·deepseek
曦月合一13 小时前
html中iframe标签 隐藏滚动条
前端·html·iframe
code_shenbing19 小时前
WPF实现打印机控制及打印
wpf
m0_5287238120 小时前
HTML中,title和h1标签的区别是什么?
前端·html