.net创建一个ActiveX控件并使用的简单例子
2008-08-04 10:23
821 查看
在很多情况下,客户往往需要在客户端实现一些复杂的功能,有些可以通过AJAX来实现,有些则是现有客户端脚本不能完成的,此时则必须通过ActiveX控件来实现。
这里给出一个用.net编写简单的ActiveX并在网页中应用的例子:
///////////////////////////////////////////////////////////////////////////////////
// AxComp.cs
// Creates a simple ActiveX component.
//
// 1. Compile into a class library, or use:
// csc /t:library AxComp.cs
// 2. Register and generate the Typelib on the client's machine with:
// regasm AxComp.dll /tlb:AxCompNet.dll /codebase
///////////////////////////////////////////////////////////////////////////////////
using System;
using System.Runtime.InteropServices;
namespace AxComponent
{
public interface IAxTest
{
string CallIt();
}
[ClassInterface(ClassInterfaceType.AutoDual)]
public class AxComp : IAxTest
{
public string CallIt()
{
return "This is a test.";
}
}
}
Code
///////////////////////////////////////////////////////////////////////////////////
// Tester.htm
// Test the ActiveX component.
///////////////////////////////////////////////////////////////////////////////////
<html>
<head>
<script language=JavaScript>
var g_axComponent = new ActiveXObject('AxComponent.AxComp');
alert(g_axComponent.CallIt());
</script>
</head>
<body>
<h1>Tester.htm</h1>
</body>
</html>
这里给出一个用.net编写简单的ActiveX并在网页中应用的例子:
///////////////////////////////////////////////////////////////////////////////////
// AxComp.cs
// Creates a simple ActiveX component.
//
// 1. Compile into a class library, or use:
// csc /t:library AxComp.cs
// 2. Register and generate the Typelib on the client's machine with:
// regasm AxComp.dll /tlb:AxCompNet.dll /codebase
///////////////////////////////////////////////////////////////////////////////////
using System;
using System.Runtime.InteropServices;
namespace AxComponent
{
public interface IAxTest
{
string CallIt();
}
[ClassInterface(ClassInterfaceType.AutoDual)]
public class AxComp : IAxTest
{
public string CallIt()
{
return "This is a test.";
}
}
}
Code
///////////////////////////////////////////////////////////////////////////////////
// Tester.htm
// Test the ActiveX component.
///////////////////////////////////////////////////////////////////////////////////
<html>
<head>
<script language=JavaScript>
var g_axComponent = new ActiveXObject('AxComponent.AxComp');
alert(g_axComponent.CallIt());
</script>
</head>
<body>
<h1>Tester.htm</h1>
</body>
</html>
相关文章推荐
- .net创建一个ActiveX控件并使用的简单例子
- 使用eclipse创建JPA-->:附带一个简单的例子
- 使用maven创建一个简单的MyBatis例子
- S1.1_Struts2_Model2 手动创建一个简单的servlet项目,未使用Struts技术
- 一个先进的App框架:使用Ionic创建一个简单的APP
- 一个epoll/aio/eventfd结合使用的简单例子
- 使用MicroService4Net 快速创建一个简单的微服务
- vb2005 创建和使用线程的简单例子
- CoreText 使用教程:以创建一个简单的杂志应用为例
- 第8章 使用Spring Web Flow--学习一个简单例子
- 使用Angular4+kendo ui for Angular+ webapi+sqlserver创建一个简单的省市选择程序(三)
- 使用JavaBean创建您的网上日历本 有的朋友曾经说过,如果有一个网上的日记本,或者一个网上的万年历能提醒自己到时去干什么事情就好了。其实呀,这样的日历本您自己也能做一个。不信你看下面的例子: 〈
- 使用Google Test的一个简单例子
- 使用boost线程的一个简单的例子
- 使用ASP.NET MVC 4 创建一个简单的应用程序
- nodejs使用express创建一个简单web应用
- 使用 CodeIgniter 创建一个简单的 Web 站点
- 在.net中使用Udp协议创建简单的聊天程序
- 使用 Fabrik 组件为 Joomla 创建一个简单的留言板
- 使用Eclipse+maven3插件开发一个Servlet3.0的简单例子