marginwidth="0" marginheight="0" src="http://218.16.120.35:65001/PC/Global/images/b.html" frameborder="0" width="728" scrolling="no" height="90">
1、ActiveX在.NET中的实现
如上图所示在.NET中使用UserControl来实现ActiveX。代码如下。
2、其中,将在HTML中使用的方法在接口AxMyControl中实现,代码如下:
3、Assembly.cs中的特殊设置:
1 // Setting ComVisible to false makes the types in this assembly not visible
2 // to COM components. If you need to access a type in this assembly from
3 // COM, set the ComVisible attribute to true on that type.
4 [assembly: ComVisible(true)]
1、ActiveX在.NET中的实现
如上图所示在.NET中使用UserControl来实现ActiveX。代码如下。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
// Add in these using clauses for this example
using System.Reflection;
using Microsoft.Win32;
namespace ActiveXDotNet
{
//[ClassInterface(ClassInterfaceType.AutoDual)]
public partial class myControl : UserControl, AxMyControl
{
public myControl()
{
InitializeComponent();
}
private String mStr_UserText;
public String UserText
{
get { return mStr_UserText + " OK"; }
set
{
mStr_UserText = value;
this.txtUserText.Text = value;
}
}
private void button1_Click(object sender, EventArgs e)
{
this.txtUserText.Text = "Hello World";
}
private void button2_Click(object sender, EventArgs e)
{
InputForm frmInput = new InputForm();
frmInput.ShowDialog();
}
}
}
2、其中,将在HTML中使用的方法在接口AxMyControl中实现,代码如下:
using System;
using System.Collections.Generic;
using System.Text;
namespace ActiveXDotNet
{
interface AxMyControl
{
String UserText { set; get; }
}
}
3、Assembly.cs中的特殊设置:
1 // Setting ComVisible to false makes the types in this assembly not visible
2 // to COM components. If you need to access a type in this assembly from
3 // COM, set the ComVisible attribute to true on that type.
4 [assembly: ComVisible(true)]