Add References and Set a License - WPF C#

This tutorial shows how to create a project, add LEADTOOLS references, and set your LEADTOOLS license in a WPF C# application.

Overview  
Summary This tutorial covers how to get started with LEADTOOLS in a WPF C# application.
Completion Time 10 minutes
Visual Studio Project Download tutorial project (8 KB)
Platform WPF C# Application
IDE Visual Studio 2019, 2022
Development License Download LEADTOOLS
Try it in another language

Required Knowledge

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.

Create the Project

Launch Visual Studio and select Create a new project.

Creating a new Visual Studio project.

Select WPF App (.NET Framework) and click Next.

Creating a new WPF App .NET Framework.

Add the project name and specify where the project will be saved to, then click Create.

Adding the Visual Studio project name and location.

Add the 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).

Add LEADTOOLS References via NuGet

Right-click the .csproj file in the Solution Explorer and select Manage NuGet Packages...

Selecting Manage NuGet Packages.

Browse for LEADTOOLS, then select any of the LEADTOOLS NuGet packages and install it. You will need to accept LEAD's End User License Agreement.

Installing LEADTOOLS NuGet packages.

Add Reference to Local LEADTOOLS DLLs

To add the LEADTOOLS references locally, perform the following steps:

In the Solution Explorer, right-click References, and select Add Reference.

Adding local assembly reference.

In the Reference Manager, select Browse and then navigate to the directory where the LEADTOOLS Assemblies are located: <INSTALL_DIR>\LEADTOOLS22\Bin\Dotnet4\x64

Select and add Leadtools.dll, then click OK. This is the LEADTOOLS Kernel DLL and will be required for any LEADTOOLS functionality.

Adding reference to Leadtools.dll.

Add the Set License Code

Now that the LEADTOOLS references have been added to the project, coding can begin. The LEADTOOLS license unlocks the LEADTOOLS features needed for the project. It must be set before any toolkit functions are 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 MainWindow.xaml in the Solution Explorer, and select View Code, or press F7, to bring up the code behind the window. Add the following statements to the using block.

C#
using System; 
using System.IO; 
using System.Windows; 
using Leadtools; 

Inside the MainWindow class, add a new method called SetLicense(). Call this new method inside the MainWindow() method. Add the code below to properly set your LEADTOOLS runtime license.

C#
void SetLicense() 
{ 
    string license = @"C:\LEADTOOLS22\Support\Common\License\LEADTOOLS.LIC"; 
    string key = File.ReadAllText(@"C:\LEADTOOLS22\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

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.

Message box indicating license has been set successfully.

Wrap-up

This tutorial showed how to create a new C# .NET Framework WPF Project, add references via NuGet or local LEADTOOLS DLLs, and set the license.

This is the basis for all C# .NET Framework WPF 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 functions.

After the SDK is purchased, the evaluation license can be replaced with a valid release license to disable the Nag Message.

See Also

Help Version 22.0.2024.3.20
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.

Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.