C # do ActiveX control problems

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.