易截截图软件、单文件、免安装、纯绿色、仅160KB

VB.NET/C# and JavaScript communication

Introduction
This article is about passing data between VB.NET/C# WinForms and JavaScript.
Before reading further, let me warn you that this article is not about ASP.NET. Concepts covered in the article are applied to Desktop applications.
Background
I was working on a project which required data transfer between my VB.NET WinForms application and the JavaScript (inside an HTML page). Along the way, I hit certain problems, and trying to resolve them cost plenty of time on the web (on Google mostly), so I thought of this article as a platform for developers looking to sort out similar issues. There isn't much detail on this topic on the web apart from a couple of Hello World examples from Microsoft on MSDN.
Starting point
OK, without any further talk, I will dig in to the subject.
Hello World
To start off, we'll start with a very simple example; all this will do is call a JavaScript function from VB.NET to display an alert with message 'Hello world'. Similarly, from the HTML page using JavaScript, we'll call a VB.NET function which will again display a messagebox with the message 'Hello world'. These are the steps you need to do to make it happen:
Calling JavaScript from VB.NET
In Visual Studio, create a new WinForms application, name it anything you like.
Add an import statement like Imports System.Security.Permissions in your form1 (main form).
Add a couple of attributes to form1, like:
Collapse Copy Code
<PermissionSet(SecurityAction.Demand, Name:="FullTrust")> _
<System.Runtime.InteropServices.ComVisibleAttribute(True)> _
Public Class Form1
End Class
All they do is tell the .NET Framework that we want fulltrust and make the class visible to COM so this class is visible to JavaScript.
Add a WebBrowser control to the form and set its url property to c:\temp\mypage.html (just an example path, you should set it to the HTML page you'll be using).
Add a Button control on the form, and on its click handler, write this code:
Collapse


相关文档:

ASP.NET(C#)常用代码30例

1. 打开新的窗口并传送参数:
  传送参数:
response.write("<script>window.open(’*.aspx?id="+this.DropDownList1.SelectIndex+"&id1="+...+"’)</script>")
  接收参数:
string a = Request.QueryString("id");
string b = Request.QueryString( ......

vb实现仿金山词霸的屏幕取词功能

今天想要做类似金山词霸屏幕取词的功能,在网上找了一些资料,发现都很复杂。既然金山词霸已经实
现了,借用之:
金山词霸中2005中带了一个XdictGrb.dll,其实是一个COM组件,并且实现了一个取词的插件框架。
其中的有以下内容:
1 接口
1.1 GrabProxy 取词代理对象
Function AdviseGrab(XDictGrabSink As IXDictGra ......

javascript写类方式之三

取前面两种的优点:
a、用构造函数来定义类属性(字段)
b、用原型方式来定义类的方法。
就有了第三种方式。这种方式貌似采用的人较多。
3、综合构造函数/原型
/**
* Person类:定义一个人,有个属性name,和一个getName方法
* @param {String} name
*/
function Person(name) {
this.name = name;
}
Pers ......

javascript写类方式之四

通过前面几篇得知javascript写类无非基于构造函数
和原型
。既然这样,我们写个工具函数来写类。
/**
* $class 写类工具函数之一
* @param {Object} constructor
* @param {Object} prototype
*/
function $class(constructor,prototype) {
var c = constructor || function(){};
var p = prototype || {}; ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号