To create an ActiveX control:
1. Create a new project "Windows Control Library", remove UserControl1.cs from the project, create a new "user Control" item and specify a name.
2. Open the project properties and select "Register for COM Interop" on the "Build" tab.
3. Open the AssenblyInfo.cs in the properties, modify [Assembly:comvisible (false)], change false to True, otherwise the compilation will appear "does not contain any type that can be registered for COM Interop (Logoff) Warning
4, compile.
To create a Web page:
1. Create a new ASP. NET Web site, select location, click Browse, select Local IIS, and then open and determine the new Web application.
2, in the appropriate place to join Default.aspx
<object classid= "Http:testactivex.dll#testactivex.picture" width= "640px" height= "480px" ></object>
Where ClassID is in the format "http: Component Name # namespace. Class".
3. Build the website.
4. Copy the components to the appropriate directory on the site.
To create an ActiveX control using C #
First create the DLL library with the following code:
Using System;
Using System.Runtime.InteropServices;
Namespace Anamespace
{
Defining Interfaces for COM components
public interface Asignatures
{
String FName ();
String SName ();
int age {get;}
}
Indicates that this class will be exposed as an interface to a COM component
[ClassInterface (Classinterfacetype.autodual)]
public class Aclass:asignatures
{
How to implement the interface concretely
public string FName ()
{
return "Imran";
}
public string SName ()
{
return "Nathani";
}
public int Age
{
get {return 24;}
}
}
}
Save the above code as AClass.cs, then compile: Csc/t:library AClass.cs
Will get a AClass.dll and then register: regasm Aclass.dll/tlb/codebase
Finally, create an HTML test page with the following content:
<script language= "JavaScript" >
<!--Load the ActiveX object--
var x = new ActiveXObject ("Anamespace.aclass");
<!--Access the Method--
Alert (X.fname ());
Alert (X.sname ());
<!--Access the property--
alert (x.age);
</script>
<body>
</body>
C # do ActiveX control problems