winform程序里有webbrower控件,嵌套这一个web程序,现在要想再web程序做的操作能让winform知道,
或者webbrower控件里的web程序如何调用winform里的方法。?
有demo最好了。谢谢各位,急求
或者webbrower控件里的web程序如何调用winform里的方法。?
有demo最好了。谢谢各位,急求
解决方案 »
- DataGridView 清空后再增加数据,内存一直增大
- 【急】C#如何实现SQL连接显示所有的数据库?
- 求助 c#检索access数据库时,提示错误SELECT 子句中包含一个保留字、拼写错误或丢失的参数,或标点符号不正确
- c# winform 大量控件时如何保存输入内容?
- 求助于数据库多个表连接的问题
- VC控件的问题
- 远程抓取数据写入到数据库(c# SqlServer)
- 改变问题
- 怎样终止线程才能不让那个ThreadAbortException出来?
- 请问:如何在C#中读写一个配置文件
- flashpaper2不能转换PDF文档到SWF格式吗?在线等....
- 无法将类型为“ADODB.StreamClass”的 COM 对象强制转换为接口类型“ADODB.Stream”
using System.Windows.Forms;namespace WindowsFormsApplication2
{
[System.Runtime.InteropServices.ComVisibleAttribute(true)]
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
webBrowser1.ObjectForScripting = this; webBrowser1.Navigate("about:blank");
webBrowser1.Document.Write(@"<script type=""text/javascript""> function WinFormShowMsg(text) { window.external.ShowMsg(text);}</script> <input id='ShowMsg' type='button' onClick='WinFormShowMsg(""www"");' >");
} public void ShowMsg(string text)
{
MessageBox.Show("WinForm弹出:" + text);
}
}
}
使用window.external
测试上面的代码
有两点需要注意:
1.[System.Runtime.InteropServices.ComVisibleAttribute(true)]
2.webBrowser1.ObjectForScripting = this;
然后再用Navigate连接这个页面
{
InitializeComponent();
this.webBrowser1.Navigate("http://localhost:9584/");
this.webBrowser1.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(webBrowser1_DocumentCompleted);
} void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
//throw new NotImplementedException(); System.Windows.Forms.HtmlDocument HTMLDocument = this.webBrowser1.Document;
System.Windows.Forms.HtmlElement closeBtn = HTMLDocument.GetElementById("ctl00$MainContent$btnClick"); //html中元素标签
closeBtn.MouseDown += new HtmlElementEventHandler(closeWindw);// // HTML点击按钮
} void closeWindw(object o, EventArgs e)
{
this.WindowState = FormWindowState.Minimized;
}