Winform与嵌入的Web浏览器控件进行交互 [英] winform interacting with embeded webbrowser contrl

查看:166
本文介绍了Winform与嵌入的Web浏览器控件进行交互的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

是否可以传递和获取值到嵌入在Winform中的Web浏览器?
如果是,您能指出我任何参考或代码示例吗?

感谢

Hello,

Is it possible to pass and get values to a web-browser embedded in winform?
if yes, can you point me to any reference or code sample

thanks

推荐答案

有些使用COM对象的方法很复杂,因为在客户端必须使用某些< object>标签,并且在后台使用com.

我更喜欢从C#调用脚本来对页面讲话
There are ways using COM objects which I find complicated because on the client side you must use some <object> tags and it is using com behind the scene.

I prefer calling a scripts to speak to the page from C#
private void RunScript(string cmd, params object[] args)
{
   var doc = WebBrowser1.Document;
   if (doc != null) doc.InvokeScript(cmd, args);
}


不幸的是,这将不会返回任何内容.
要取回数据,您可以调用本地TCP端口.如果您的程序已经必须提供图片或页面,则是理想选择.
如果您愿意,可以使用javascript更改标题. (此示例中也使用jQuery):


This unfortunately won''t return anything.
To get data back you can either make a call to a local TCP port. If your program already must provide pictures or pages it is ideal.
If you prefer you can use javascript to change the title. (this is also using jQuery in this sample):


(" ).click(函数(){ 文档 .title = " +
(".button").click(function () { document.title = "#click:" +


().attr(' id'); });
(this).attr('id'); });


然后在您的程序中很容易


Then it is easy in your program

void webBrowser1_DocumentTitleChanged(object sender, EventArgs e)
{
   if (webBrowser1.DocumentTitle.StartsWith("#click:"))
   {
      ...
   }
}

</object>

</object>


这篇关于Winform与嵌入的Web浏览器控件进行交互的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆