惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园_首页
量子位
D
DataBreaches.Net
博客园 - 司徒正美
J
Java Code Geeks
博客园 - 【当耐特】
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
aimingoo的专栏
aimingoo的专栏
B
Blog
The Cloudflare Blog
D
Docker
I
InfoQ
爱范儿
爱范儿
MongoDB | Blog
MongoDB | Blog
腾讯CDC
月光博客
月光博客
Hugging Face - Blog
Hugging Face - Blog
Microsoft Azure Blog
Microsoft Azure Blog
Vercel News
Vercel News
阮一峰的网络日志
阮一峰的网络日志
小众软件
小众软件
S
SegmentFault 最新的问题
GbyAI
GbyAI
有赞技术团队
有赞技术团队

博客园 - 笑缘

Oxite开源内容管理平台 Informatica Data Quality英文培训文档 最近开始学习BI了 我们需要更团结 希望大家奔走先告(转) 学会忘记,学会原谅! .NET Framework 开源咯 软件项目团队有效性和五原则 提高程序的传输效率,减少带宽的占用,启用IIS6中GZip压缩 - 笑缘 - 博客园 分页存储过程(收藏) asp.net页面的生存周期 C#异步多线程AD浏览器(一) 使用HttpContext的User属性来实现用户验证 Visual Studio Team System 2008 Setup 怎样让.Net2.0的Membership使用已存在的Sql Server2000/2005数据库(转) 五种提高 SQL 性能的方法(转。收藏) SharePoint2007开发(二)Hello WebPart SharePoint2007开发(一)部署 获取Setup文件的运行路径 将数据库表中的数据生成Insert脚本的存储过程(改版)
C#实现Web程序调用Windows程序的方法
笑缘 · 2007-12-03 · via 博客园 - 笑缘

Posted on 2007-12-03 12:20  笑缘  阅读(1090)  评论(2)    收藏  举报

using System;
using System.Windows.Forms;
using System.Security.Permissions;

[PermissionSet(SecurityAction.Demand, Name
="FullTrust")]
[System.Runtime.InteropServices.ComVisibleAttribute(
true)]
public class Form1 : Form
{
    
private WebBrowser webBrowser1 = new WebBrowser();
    
private Button button1 = new Button();

    [STAThread]
    
public static void Main()
    
{
        Application.EnableVisualStyles();
        Application.Run(
new Form1());
    }


    
public Form1()
    
{
        button1.Text 
= "call script code from client code";
        button1.Dock 
= DockStyle.Top;
        button1.Click 
+= new EventHandler(button1_Click);
        webBrowser1.Dock 
= DockStyle.Fill;
        Controls.Add(webBrowser1);
        Controls.Add(button1);
        Load 
+= new EventHandler(Form1_Load);
    }


    
private void Form1_Load(object sender, EventArgs e)
    
{
        webBrowser1.AllowWebBrowserDrop 
= false;
        webBrowser1.IsWebBrowserContextMenuEnabled 
= false;
        webBrowser1.WebBrowserShortcutsEnabled 
= false;
        webBrowser1.ObjectForScripting 
= this;
        
// Uncomment the following line when you are finished debugging.
        
//webBrowser1.ScriptErrorsSuppressed = true;

        webBrowser1.DocumentText 
=
            
"<html><head><script>" +
            
"function test(message) { alert(message); }" +
            
"</script></head><body><button " +
            
"onclick=\"window.external.Test('called from script code')\">" +
            
"call client code from script code</button>" +
            
"</body></html>";
    }


    
public void Test(String message)
    
{
        MessageBox.Show(message, 
"client code");
    }


    
private void button1_Click(object sender, EventArgs e)
    
{
        webBrowser1.Document.InvokeScript(
"test",
            
new String[] "called from client code" });
    }


}


刷新页面返回顶部