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)
        {
        }
    }
相关推荐
Larcher1 小时前
新手也能学会,100行代码玩AI LOGO
前端·llm·html
小月鸭1 小时前
如何理解HTML语义化
前端·html
BBB努力学习程序设计4 小时前
CSS Sprite技术:用“雪碧图”提升网站性能的魔法
前端·html
BBB努力学习程序设计4 小时前
CSS3渐变:用代码描绘色彩的流动之美
前端·html
阳懿7 小时前
meta-llama-3-8B下载失败解决。
前端·javascript·html
谢彦超oooo10 小时前
HTML5 与前端开发要点
前端·html·html5
STUPID MAN1 天前
Linux使用tomcat发布vue打包的dist或html
linux·vue.js·tomcat·html
hashiqimiya1 天前
html的input的required
java·前端·html
我命由我123451 天前
HTML - 换行标签的 3 种写法(<br>、<br/>、<br />)
前端·javascript·css·html·css3·html5·js
不坑老师1 天前
不坑盒子的插入网页功能是完全免费的!
前端·html