|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
IntroductionWe often need to reuse and extend an ActiveX control developed by other vendors in real .NET applications. There are articles and user documents on how to import an ActiveX control into Visual Studio .NET, but we don’t see much on how to customize an imported ActiveX control in the .NET environment, especially with the C# code generated by the utility AxImp.exe. In this article, we present step-by-step instructions on how to import and extend an ActiveX control in the .NET environment. We use Microsoft Calendar Control as our example. The sample code shows a customized Calendar Control that allows user to create daily note for each day; when a day is selected, a note will show in a box like a tooltip. Importing ActiveX Control in Visual Studio .NETImporting an ActiveX control inside Visual Studio .NET is easy, you can just simply place your mouse cursor inside Toolbox window, right click the mouse, then you see the “Customize Toolbox” window, in this window, select the “COM components” tab, then select the ActiveX control you want to import. Here is the window with a selection of Calendar Control:
For the imported Calendar Control, Studio will create a .NET “wrapper” with a type of To customize the Calendar Control, you use public class MyCalendar : AXMSACAL.AxCalendar
{
//customize it here
}
You build
This problem is due to: “by default, the When we try to customize the Calendar Control in this way, we run into lots of problems mainly due to the fact that the .NET generated class Importing ActiveX Control using AxImp.exeTo import the Calendar Control using AxImp.exe with source code generation, you can use a command like: AxImp /source activex_control_path_name
The following screen shows the importing of Calendar Control in command line and its output:
As you can see from the above screen, two DLLs and a C# source code are generated. The next step is to create a Windows Control Library project with Visual Studio .NET and add AxMSACAL.cs into the project. You need to copy the AxMSACAL.cs MSACAL.dll into the project directory, we don’t need the AxMSACAL.dll since we will build a customized DLL of our own. By default, AxImp generates AxMSACAL.cs like this: [assembly: System.Reflection.AssemblyVersion("7.0.0.0")]
[assembly:
System.Windows.Forms.AxHost.TypeLibraryTimeStamp("6/26/1998 12:00:00 AM")]
namespace AxMSACAL {
[System.Windows.Forms.AxHost.ClsidAttribute(
"{8e27c92b-1264-101c-8a2f-040224009c02}")]
[System.ComponentModel.DesignTimeVisibleAttribute(true)]
[System.ComponentModel.DefaultEvent("AfterUpdate")]
[System.ComponentModel.DefaultProperty("_Value")]
public class AxCalendar : System.Windows.Forms.AxHost {
private MSACAL.ICalendar ocx;
private AxCalendarEventMulticaster eventMulticaster;
private System.Windows.Forms.AxHost.ConnectionPointCookie cookie;
// other stuff ommited
}
}
In order to build this control into a DLL, you need to do the following:
Extending ActiveX ControlTo customize the Calendar Control, you need to do the following:
SummaryIn this article, we showed how to use AxImp to import an ActiveX control with C# code generation, then customize the control with the generated code and extend it.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||