西西軟件園多重安全檢測(cè)下載網(wǎng)站、值得信賴的軟件下載站!
軟件
軟件
文章
搜索

首頁編程開發(fā)C#.NET → C#中winform與webbrower控件交互問題

C#中winform與webbrower控件交互問題

相關(guān)軟件相關(guān)文章發(fā)表評(píng)論 來源:本站整理時(shí)間:2010/11/19 16:47:24字體大。A-A+

作者:佚名點(diǎn)擊:293次評(píng)論:0次標(biāo)簽: winform webbrower

  • 類型:遠(yuǎn)程監(jiān)控大。4.6M語言:中文 評(píng)分:5.7
  • 標(biāo)簽:
立即下載

我想實(shí)現(xiàn) js調(diào)用 winform里面的方法,通過webbrower控件和winform進(jìn)行交互。不知道怎么弄啊。
我在網(wǎng)上找了些資料,說的在js里面寫 window.external.方法名();
但是沒用啊,js報(bào)錯(cuò)。。。

this.webBrowser1.Url = new Uri(GetDefaultUrl());

C# code
using System;
using System.Windows.Forms;
using System.Threading;
using System.Runtime.InteropServices;

namespace WindowsFormsApplication1
{
[System.Runtime.InteropServices.ComVisibleAttribute(true)]
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
webBrowser1.ObjectForScripting = this;
}

public void Func(string str)
{
MessageBox.Show(str);
}

private void Form1_Load(object sender, EventArgs e)
{
webBrowser1.Navigate("about:blank");

webBrowser1.Document.Write("<script> function ButonClick() { window.external.Func('test');}</script><input type='button' onclick='ButonClick();'>test");
}
}
}

設(shè)置下面兩個(gè)地方
C# code
[System.Runtime.InteropServices.ComVisibleAttribute(true)]
public partial class Form1 : Form

webBrowser1.ObjectForScripting = this;

    相關(guān)評(píng)論

    閱讀本文后您有什么感想? 已有人給出評(píng)價(jià)!

    • 8 喜歡喜歡
    • 3 頂
    • 1 難過難過
    • 5 囧
    • 3 圍觀圍觀
    • 2 無聊無聊

    熱門評(píng)論

    最新評(píng)論

    發(fā)表評(píng)論 查看所有評(píng)論(0)

    昵稱:
    表情: 高興 可 汗 我不要 害羞 好 下下下 送花 屎 親親
    字?jǐn)?shù): 0/500 (您的評(píng)論需要經(jīng)過審核才能顯示)