C # Develop ActiveX for accessing SQL data, moving mouse events, drawing, and Javascript operations ActiveX

Source: Internet
Author: User

Thank you for reprinting and referencing this article! Please keep the following link if possible during reprinting. I would like to thank you!
Address: http://www.bmpj.net/thread-1206-1-1.html

I,
Development Environment
1. VS2005 C #
2. The accessed database SQL2000
2. Establish project and project preparation
1. Create a "Windows control library", name it "MyControl", and change the "UserControl1" control to "WEB ".
2. Select "MyControl" project "properties", set "register for COM Interop" to "select status", and select "generate serialization assembly" to "off" status, generally, it can be set to "automatic.

3. Find the "AssemblyInfo. cs" file under the project,
(1) Add code:

[Assembly: AllowPartiallyTrustedCallers ()]

Note: Some trusted codes are allowed to call assembly with strong names. Without this declaration, such an assembly can be used only for fully trusted calls.

(2) Change "[assembly: ComVisible (false)]" to "[assembly: ComVisible (true)]"
Note: The ComVisible attribute controls the accessibility of individual hosted types, members, or all types to COM in a dataset.

(3) Comment out "[assembly: Guid (" 8a4af041-84fd-4d8c-aed2-3916f6135bf4.

Every time a project is regenerated, The classid changes and the classid referenced on the webpage is not fixed. Therefore, this line of code is useless (this is proved by practice and the reason is unknown ).

4. Find the project code file "WEB. cs ". Adds the Guid attribute. You can select "tool"> "create GUID" in the development environment to create a unique GUID.
(1) Add a reference to the namespace "using System. Runtime. InteropServices.

(2)
Add "[Guid (" F7D892EA-9546-3BEB-A8D9 -67A 859A 407D6 ")]"

Note: a fixed classid is defined for this component of this project to facilitate the reference of the classid object on the webpage. It also replaces the "assembly: Guid" attribute.

At this time, the project environment is ready. You can write the code below.
5. After the project is generated, check whether the Guid of this component on the local machine is consistent with the one we set. If they are inconsistent, we cannot correctly reference the classid, the corresponding components cannot be displayed on the webpage.
Find the OleView. Exe program under the "Microsoft Visual Studio 8 \ Common7 \ Tools \ Bin" directory, run the program, and select ". NET Category ",

III,
Web pages reference the MyControl project component, that is, ActiveX in the general sense.

<Object id = "MyControl" name = "MyControl" classid = "clsid: F7D892EA-9546-3BEB-A8D9-67A859A407D6" Width = "500" Height = "400" VIEWASTEXT/>
Note: Check whether the classid and Guid settings are consistent.
4. demonstrate the effects of SQL data access, moving mouse events, painting, and javascript operation components.

 

Source code, database, instructions for downloading

Http://dl.dbank.com/c0sc41jhxt

Related Article

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.