Microsoft .NET controls give developers the leverage they need to build modular solutions. A developer can design custom controls from a myriad of existing controls and embed the custom control into a Windows Form or another control. With some additional code, one can also embed those controls in a Web Form. Using the host control container called TClrContainer will allow you to place .net controls on delphi VCL forms. The TClrContainer Control is a container control to host a group of .net controls. It is used to group collections of .Net controls. This control type is defined in the namespace CNClrLib.Comp .
Creating a ClrContainer
We can create a ClrContainer Control using the Forms designer at design-time or using the TClrContainer class in code at run-time.
To create a Panel Control at design-time, you can drag and drop a Panel Control from the Toolbox to a Form in Delphi IDE. After you dragging and dropping a ClrContainer Control to the Form, the control looks like Figure 1. Once a ClrContainer is on the form, you can move it around and resize it using the mouse and set its properties and events.
Creating a ClrContainer Control at run-time is merely a work of creating an instance of the TClrContainer class, setting its properties and adding the TClrContainer to the form controls. The first step to create a dynamic ClrContainer is to create an instance of the TClrContainer class. The following code snippet creates a TClrContainer Control object.
Adding .net controls to the ClrContainer can be done at runtime. Use the overload method AddClrControl to add the instance of the .net control created to the container control. The following code snipper demonstrates how an instance of a .Net DatagridView control can be added to the ClrContainer.
The example below demonstrates how to load data from the database, bind it to a DatagridView control which is added to the ClrContainer and display the gridview result on the VCL form.