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)
        {
        }
    }
相关推荐
夏幻灵6 小时前
Express 静态资源托管详解:从本地 HTML 到 express.static()
前端·html·express
小羊没烦恼!20 小时前
T-SQL查询进阶--理解SQL SERVER中的分区表
服务器·开发语言·前端·javascript·html
ShineWinsu1 天前
对于JavaScript:初识JavaScript以及输入输出
java·开发语言·前端·javascript·css·面试·html
donk13141 天前
React Native for OpenHarmony 实战:三方库 react-native-circular-action-menu 的鸿蒙化适配指南
javascript·分布式·react native·react.js·wpf·harmonyos
码银1 天前
【web】基于HTML/CSS,JavaScript + Three.js做3D流程图
前端·css·html
小熊在忙fpga1 天前
N32G430芯片的flash表示
前端·javascript·html
java1234_小锋1 天前
【技术专题】HTML5 网页技术 - HTML5 表格标签
前端·html·html5
东鹏特饮1 天前
全屏黑客终端(自动入侵 + 进度条)
html·恶搞
燕落南枝1 天前
HTML 学习笔记:从基础到音频标签
笔记·学习·html
java1234_小锋2 天前
【技术专题】HTML5 网页技术 - HTML5简介 & HTML5 文档结构
前端·html·html5