C#编写ActiveX控件有关问题。IE中无法触发事件
C#编写ActiveX控件问题。IE中无法触发事件
C# 编写的 ActiveX 控件中含有事件。在HTML中无法触发,始终提示 事件为空!
HTML代码如下
<html>
<body bgcolor=’#223344’>
<Script Language=JavaScript>
function test()
{
helloworld.TestVoid( "test11 ");
}
</Script>
<object id= "helloworld "
classid= "clsid:A69AC4D2-7A3E-45f8-93D5-84F39E302116 " Width= "184 " Height= "96 "
>
</object>
<script for= "helloworld " event= "OnTestEvent(msg) " language= "javascript ">
alert(msg);
</script>
<input type= "button " onclick= "test() " value=’Click’>
</body>
</html>
AceiveX源码
public delegate void TestEvent(string msg);
[Guid( "A69AC4D2-7A3E-45f8-93D5-84F39E302116 ")]
[ComVisible(true)]
[ClassInterface(ClassInterfaceType.AutoDual)]
[ComSourceInterfaces(typeof(TestOcx.IUserControl1))]
public class UserControl1 : UserControl, IObjectSafety, TestOcx.IUserControl1
{
public event TestEvent OnTestEvent;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
/// <param name= "disposing "> 如果应释放托管资源,为 true;否则为 false。 </param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region 组件设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要
C# 编写的 ActiveX 控件中含有事件。在HTML中无法触发,始终提示 事件为空!
HTML代码如下
<html>
<body bgcolor=’#223344’>
<Script Language=JavaScript>
function test()
{
helloworld.TestVoid( "test11 ");
}
</Script>
<object id= "helloworld "
classid= "clsid:A69AC4D2-7A3E-45f8-93D5-84F39E302116 " Width= "184 " Height= "96 "
>
</object>
<script for= "helloworld " event= "OnTestEvent(msg) " language= "javascript ">
alert(msg);
</script>
<input type= "button " onclick= "test() " value=’Click’>
</body>
</html>
AceiveX源码
public delegate void TestEvent(string msg);
[Guid( "A69AC4D2-7A3E-45f8-93D5-84F39E302116 ")]
[ComVisible(true)]
[ClassInterface(ClassInterfaceType.AutoDual)]
[ComSourceInterfaces(typeof(TestOcx.IUserControl1))]
public class UserControl1 : UserControl, IObjectSafety, TestOcx.IUserControl1
{
public event TestEvent OnTestEvent;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
/// <param name= "disposing "> 如果应释放托管资源,为 true;否则为 false。 </param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region 组件设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要