This article is about creating
ActiveX controls using a DotNet Usercontrol in Csharp. You can design
all ActiveX features like: properties, methods and events.
Environment:
Visual Studio(2005) Csharp
How to Do This
1. Create a Usercontrol using Visual Studio (C#):
2. Configure the project properties:
3. Modify the usercontrol interface:
Note:Make sur you added the EVENTS class:
[ClassInterface(ClassInterfaceType.AutoDual),
ComSourceInterfaces(typeof(UserControlEvents))]
using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Data; using System.Text; using System.Windows.Forms; // Add references using System.Runtime.InteropServices; using System.Reflection; using Microsoft.Win32;
|
4. Add the register/unregister section in the source code
// register COM ActiveX object [ComRegisterFunction()]
|
5. Add an ActiveX property:
// ActiveX properties (Get/Set) ////////////////////////////////////////////////////////////////// private int ptextVal;
ptextVal = value; numericUpDown1.Value = ptextVal; } }
|
6. Add an ActiveX method:
// ActiveX methods/functions ////////////////////////////////////////////////////////////////// public interface ICOMCallable
{ int GetTextBoxValue(); } public int
|
7. Add an ActiveX event:
// Eventhandler interface ////////////////////////////////////////////////////////////////// public public public private
|
8. Register the ActiveX on your PC:
Register the new ActiveX on your computer using the
command: RegAsm.exe CsharpWindowsActiveX.dll
9. Test your ActiveX:
Use the TSTCon32.exe tool from Visul Studio to test the
ActiveX: