This tutorial shows how to create a project, add references, and set the license using the LEADTOOLS SDK in a WinForms C# .NET 6 application.
Overview | |
---|---|
Summary | This tutorial covers how to set a license in a WinForms C# application. |
Completion Time | 10 minutes |
Visual Studio Project | Download tutorial project (5 KB) |
Platform | .NET 6 WinForms C# Application |
IDE | Visual Studio 2022 |
Development License | Download LEADTOOLS |
Try it in another language |
|
Before any functionality from the SDK can be leveraged, a valid runtime license will have to be set.
For instructions on how to obtain a runtime license refer to Obtaining a License.
Launch Visual Studio and select Create a new project.
Select Windows Forms App and click Next.
Add the project name, and specify the location where the project to be saved to, then click Next.
Set the project's framework to .NET 6.0 and click Create.
Add the necessary LEADTOOLS references. The references needed depend upon the purpose of the project. References can be added by one or the other of the following two methods (but not both).
Right-click the C# project in the Solution Explorer and select Manage NuGet Packages...
Browse for LEADTOOLS, then select any of the LEADTOOLS NuGet packages and install it. Accept LEAD's End User License Agreement.
To add the LEADTOOLS references locally, perform the following steps:
In the Solution Explorer, right-click Dependencies, and select Add Project Reference.
In the Reference Manager, select Browse and then navigate to the directory where the LEADTOOLS Assemblies are located: <INSTALL_DIR>\LEADTOOLS23\Bin\net
Select and add Leadtools.dll
, then click OK.
Now that the LEADTOOLS references have been added to the project, coding can begin. The License unlocks the LEADTOOLS features needed for the project. It must be set before any toolkit function is called. The exact function called depends on the platform used. For details, refer to Setting a Runtime License.
There are two types of runtime licenses:
Right-click on Form1.cs
in the Solution Explorer, and select View Code to bring up the code behind the form. Add the following statement to the using
block.
using Leadtools;
In the Form1
class add a new method called SetLicense()
and call it in the Form1()
constructor. Add the code below to properly set your LEADTOOLS runtime license.
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
SetLicense();
}
static void SetLicense()
{
string license = @"C:\LEADTOOLS23\Support\Common\License\LEADTOOLS.LIC";
string key = File.ReadAllText(@"C:\LEADTOOLS23\Support\Common\License\LEADTOOLS.LIC.KEY");
RasterSupport.SetLicense(license, key);
if (RasterSupport.KernelExpired)
MessageBox.Show("License file invalid or expired.");
else
MessageBox.Show("License file set successfully");
}
}
Run the project by pressing F5, or by selecting Debug -> Start Debugging.
If the steps are followed correctly, the application runs and a message box displays License file set successfully
.
This tutorial showed how to create a new C# .NET 6 WinForms Project, add references via NuGet or local LEADTOOLS DLLs, and set the license.
This is the basis for all C# .NET 6 WinForms applications using the LEADTOOLS SDK. All functionality in the SDK is unlocked via setting a license. SetLicense
must be called before calling any other LEADTOOLS SDK methods.
After the SDK is purchased, the evaluation license can be replaced with a valid release license to disable the Nag Message.