winform調(diào)用javascript的小例子
更新時間:2013年05月03日 11:39:15 作者:
winform調(diào)用javascript的小例子,需要的朋友可以參考一下
復制代碼 代碼如下:
<html>
<head>
<title></title>
<script type="text/javascript">
function ShowMessage(message)
{
alert(message);
}
function ShowWinFormsMessage() {
var msg = document.getElementById('txtMessage').value;
return window.external.ShowMessage(msg);
}
</script>
</head>
<body>
<input type="text" id="txtMessage" />
<input type="button" value="Show Message" onclick="ShowWinFormsMessage()" />
</body>
</html>
復制代碼 代碼如下:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace WebBrowserJavaScriptExample
{
public partial class frmMain : Form
{
public frmMain()
{
InitializeComponent();
webBrowser1.ObjectForScripting = new ScriptManager(this);
}
private void btnShowMessage_Click(object sender, EventArgs e)
{
object[] o = new object[1];
o[0]=txtMessage.Text;
object result = this.webBrowser1.Document.InvokeScript("ShowMessage", o);
}
private void frmMain_Load(object sender, EventArgs e)
{
this.webBrowser1.Navigate(@"E:\Projects\2010\WebBrowserJavaScriptExample\WebBrowserJavaScriptExample\TestPage.htm");
}
[ComVisible(true)]
public class ScriptManager
{
frmMain _form;
public ScriptManager(frmMain form)
{
_form = form;
}
public void ShowMessage(object obj)
{
MessageBox.Show(obj.ToString());
}
}
}
}
您可能感興趣的文章:
- C#調(diào)用Java代碼的方法介紹
- C#調(diào)用Java類的實現(xiàn)方法
- C#/Java連接sqlite與使用技巧
- C# 調(diào)用 JavaWebservice服務遇到的問題匯總
- C#通過html調(diào)用WinForm的方法
- Winform實現(xiàn)調(diào)用asp.net數(shù)據(jù)接口實例
- WinForm窗體調(diào)用WCF服務窗體卡死問題
- C# Winform 調(diào)用系統(tǒng)接口操作 INI 配置文件的代碼
- 在多線程中調(diào)用winform窗體控件的實現(xiàn)方法
- WinForm調(diào)用jar包的方法分析
相關(guān)文章
關(guān)于C#泛型列表List<T>的基本用法總結(jié)
本篇文章主要是對C#中泛型列表List<T>的基本用法進行了詳細的總結(jié)介紹,需要的朋友可以過來參考下,希望對大家有所幫助2014-01-01
DevExpress SplitContainerControl用法總結(jié)
這篇文章主要介紹了DevExpress SplitContainerControl用法,對初學者有一定的參考借鑒價值,需要的朋友可以參考下2014-08-08
WPF實現(xiàn)Interaction框架的Behavior擴展
這篇文章介紹了WPF實現(xiàn)Interaction框架Behavior擴展的方法,文中通過示例代碼介紹的非常詳細。對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2022-06-06
C#判斷字符串中內(nèi)容是否為純數(shù)字的詳細教程
在進行C#編程時候,有的時候我們需要判斷一個字符串是否是數(shù)字字符串,下面這篇文章主要給大家介紹了關(guān)于C#判斷字符串中內(nèi)容是否為純數(shù)字的詳細教程,文中通過實例代碼介紹的非常詳細,需要的朋友可以參考下2023-04-04
Unity?制作一個分數(shù)統(tǒng)計系統(tǒng)
項目中經(jīng)常遇到分數(shù)統(tǒng)計的需求,例如操作正確則計分,相反則不計分失去該項分數(shù),為了應對需求需要一個分數(shù)統(tǒng)計系統(tǒng)。本文主要介紹了通過Unity實現(xiàn)這樣的一個計分系統(tǒng),快來跟隨小編一起學習吧2021-12-12

