Dynamically creating an instance of csXImage in Visual Basic .NET or C#

When csXImage is dropped on a form in Visual Studio, the references and licence are imported automatically. This is not the case if the control is instantiated dynamically from code. The code fragments below show how to import the licence, which is the text inside the .lic file. The examples show the trial version, but the licence for the full version can be found by opening the licence file in a text editor.

A quick method of importing the references is to drop a control onto the form and then delete it.

Once the instance is created, the control is given a size and the LoadDialog method is called to load an image. This is just to show that it is working. The control could be used without displaying it.

Example 1 - VB.NET

Dim MyImageBox As New AxcsXImageTrial.AxImageBox()
Dim f As System.Reflection.FieldInfo
f = GetType(AxHost).GetField("licenseKey",
Reflection.BindingFlags.NonPublic _
  Or Reflection.BindingFlags.Instance)
f.SetValue(MyImageBox, "{62E57FD0-1CCD-11D7-8344-00C1261173F0}")
Controls.Add(MyImageBox)
MyImageBox.Show()
MyImageBox.Left = 100
MyImageBox.Top = 100
MyImageBox.Width = 300
MyImageBox.Height = 300
MyImageBox.LoadDialog()

Example 2 - C#

AxcsXImageTrial.AxImageBox MyImageBox = new AxcsXImageTrial.AxImageBox();
System.Reflection.FieldInfo f;
f = typeof(AxHost).GetField("licenseKey", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
f.SetValue(MyImageBox, "{62E57FD0-1CCD-11D7-8344-00C1261173F0}");
Controls.Add(MyImageBox);
MyImageBox.Show();
MyImageBox.Left = 100;
MyImageBox.Top = 100;
MyImageBox.Width = 300;
MyImageBox.Height = 300;
MyImageBox.LoadDialog();

Cookies

This site uses cookies for functionality, traffic analysis and for targeted advertising. Click the Accept button to accept our Cookie Policy. The Cookie Policy page offers configuration for a reduced set of cookies for this site.