首先,建立一个WinForm控件项目HelloWorld,并拖入一个Label控件,文字设为HelloWorld
UserControl1.cs内容如下:
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
namespace HelloWorld
{
/**////
/// UserControl1 的摘要说明。
///
public class Demo : System.Windows.Forms.UserControl
{
private System.Windows.Forms.Label label1;
/**////
/// 必需的设计器变量。
///
private System.ComponentModel.Container components = null;
public Demo()
{
// 该调用是 Windows.Forms 窗体设计器所必需的。
InitializeComponent();
// TODO: 在 InitComponent 调用后添加任何初始化
}
/**////
/// 清理所有正在使用的资源。
///
protected override void Dispose( bool disposing )
{
if( disposing )
{
if( components != null )
components.Dispose();
}
base.Dispose( disposing );
}
组件设计器生成的代码#region 组件设计器生成的代码
/**////
/// 设计器支持所需的方法 - 不要使用代码编辑器
/// 修改此方法的内容。
///
private void InitializeComponent()
{
this.label1 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// label1
//
this.label1.Location = new System.Drawing.Point(32, 32);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(120, 32);
this.label1.TabIndex = 0;
this.label1.Text = "HelloWorld";
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// Demo
//
this.Controls.Add(this.label1);
this.Name = "Demo";
this.Size = new System.Drawing.Size(184, 96);
this.ResumeLayout(false);
}
#endregion
}
}
此时编译项目,可以生成HelloWorld.dll。将此dll拷贝到IIS的虚拟根目录下,然后建立一个helloworld.htm的文件,html代码如下:
不要走入误区,其实c#是写不了Activex控件的,即使弄出来也不叫Activex控件而叫windows控件,同时客户端需要安装.Net运行时环境(关键),否则运行不了,除非Vista普及了用c#写才合适。所以本人不推荐你用琢磨这个东西,因为用微软的观点来说Activex是过时的技术