How do I develop .NET Windows Forms applications that manage movement?

Last reviewed: 10/4/2012

HOW Article ID: H101205

The information in this article applies to:

  • KinectKit

Summary

You can develop .NET Windows Forms applications that manage Kinect sensors using your favorite .NET Windows Forms development tools. This includes development environments such as Microsoft Visual C# .NET, Microsoft Visual Basic .NET, and Embarcadero Delphi Prism.

More Information

KinectKit includes Windows Forms compatible .NET assemblies compiled with .NET Framework V4 and V4.5 to support your application's target framework.

To access the KinectKit .NET classes within your application, add them to your project References:

  1. Within your .NET project, right click on the References folder in C# or Open MyProject in VB and select the References tab.
  2. For .NET V4 applications, add references to the KinectKit .NET assemblies:
    1. Program Files\Chant\KinectKit\Win32\NET\libv4\Chant.KinectKit.dll and
    2. Program Files\Chant\KinectKit\Win32\NET\libv4\Chant.Shared.dll.
  3. For .NET V4.5 applications, add references to the KinectKit .NET assemblies:
    1. Program Files\Chant\KinectKit\Win32\NET\libv45\Chant.KinectKit.dll and
    2. Program Files\Chant\KinectKit\Win32\NET\libv45\Chant.Shared.dll.
  1. Within your .NET project, right click on the References folder in C# or Open MyProject in VB and select the References tab.
  2. For .NET V4 applications, add references to the KinectKit .NET assemblies:
    1. Program Files\Chant\KinectKit\Win64\NET\libv4\Chant.KinectKit.dll and
    2. Program Files\Chant\KinectKit\Win64\NET\libv4\Chant.Shared.dll.
  3. For .NET V4.5 applications, add references to the KinectKit .NET assemblies:
    1. Program Files\Chant\KinectKit\Win64\NET\libv45\Chant.KinectKit.dll and
    2. Program Files\Chant\KinectKit\Win64\NET\libv45\Chant.Shared.dll.

To access the KinectKit .NET classes within your application, add references to the KinectKit assemblies in your code:


using System;
...
using Chant.KinectKit;
using Chant.Shared;
    

uses
    Chant.Shared,
    Chant.KinectKit,
    ...
    

Imports Chant.KinectKit
Imports Chant.Shared
Class MainWindow
...
    

Platform Target

Set the project Platform target to either x86 for 32-bit application or x64 for 64-bit application as follows:

Within your C# project

  1. Select the Build tab under project properties.
  2. Select x86 or x64 in the Platform target dropdown list.

Within your Delphi Prism project

  1. Select the Build tab under project properties.
  2. Select x86 or x64 in the Platform target dropdown list.

Within your VB .NET Project

  1. Select the Compile tab under project properties.
  2. Press the Advanced Compile Options... button.
  3. Select x86 or x64 in the Target CPU dropdown list.

Object Instantiation

Declare a global variable for the ChantKM class, instantiate an instance, add the event handler, and set the license and serial properties.


    private Chant.KinectKit.NChantKM NChantKM1;
    public MainWindow()
    {
        InitializeComponent();
        // Instantiate NChantKM object
        NChantKM1 = new NChantKM();
        // Setup event callback handler
        NChantKM1.HasEvent += this.NChantKM1_HasEvent;
        // Set license properties
        NChantKM1.SetStringProperty(ChantStringProperty.CSPLicense, "LicenseRegistrationNumber");
        NChantKM1.SetStringProperty(ChantStringProperty.CSPSerials, "LicenseSerialNumber");
    }
    

    Window1 = public partial class(System.Windows.Window)
    private
    NChantKM1: NChantKM;

    public
    constructor;
    method NChantKM1_HasEvent(sender: System.Object; e: HasEventArgs);
    end;
     
    implementation

    constructor Window1;
    begin
      InitializeComponent();
      NChantKM1 := new NChantKM();
      NChantKM1.HasEvent += NChantKM1_HasEvent;
      // Set license properties
      NChantKM1.SetStringProperty(ChantStringProperty.CSPLicense,'LicenseRegistrationNumber');
      NChantKM1.SetStringProperty(ChantStringProperty.CSPSerials,'LicenseSerialNumber');
    end;
    

    Dim WithEvents NChantKM1 As NChantKM

    Private Sub Window_Loaded(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles MyBase.Loaded
        NChantKM1 = New NChantKM()

        ' Set license properties
        NChantKM1.SetStringProperty(ChantStringProperty.CSPLicense, "LicenseRegistrationNumber")
        NChantKM1.SetStringProperty(ChantStringProperty.CSPSerials, "LicenseSerialNumber")

        ...

    End Sub
    

Event Callbacks

Event callbacks are the mechanism in which the component library communications information back to the application such as compilation is complete or there was an error.


    private void NChantKM1_HasEvent(object sender, HasEventArgs e)
    {
        // Get the number of events
        int numberOfEvents = NChantKM1.GetResourceCount(ChantSpeechResource.CSREvent, 0, 0);
        for (int i = 0; i < numberOfEvents; i++)
        {
            // Get the event from the event queue
            NChantKMEvent nChantKMEvent = NChantKM1.GetChantKMEvent(0);
            switch (nChantKMEvent.ChantCallback)
            {
                case ChantCallback.CCKSStatusChanged:
                    {
                        ...
                        break;
                    }
                default:
                    break;
            }
            // Remove the event from the event queue
            NChantKM1.RemoveResource(ChantSpeechResource.CSREvent, 0);
        }
    }
    

    method Window1.NChantKM1_HasEvent(sender: System.Object; e: HasEventArgs);
    var
      i: integer;
      numberOfEvents: integer;
      oChantKMEvent: NChantKMEvent;
    begin
        numberOfEvents := NChantKM1.GetResourceCount(ChantSpeechResource.CSREvent,0,0);
        for i := 0 To numberOfEvents - 1 do
        begin
          // Get the event from the event queue
          oChantKMEvent := NChantKM1.GetChantKMEvent(0);
          case oChantKMEvent.ChantCallback of
            ChantCallback.CCKSStatusChanged:
            begin
              ...
            end;
          end;
          // Remove the event from the event queue
          NChantKM1.RemoveResource(ChantSpeechResource.CSREvent, 0);
         end;
    end;
    

    Private Sub NChantKM1_HasEvent(ByVal sender As System.Object, ByVal e As HasEventArgs) Handles NChantKM1.HasEvent
        Dim I As Integer
        Dim numberOfEvents As Integer
        Dim nChantKMEvent As NChantKMEvent
        ' Get the number of events
        numberOfEvents = NChantKM1.GetResourceCount(ChantSpeechResource.CSREvent, 0, 0)
        For I = 0 To numberOfEvents - 1
            ' Get the event from the event queue
            nChantKMEvent = NChantKM1.GetChantKMEvent(0)
            Select Case nChantKMEvent.ChantCallback
                Case ChantCallback.CCKSStatusChanged
                    ...
            End Select
            ' Remove the event from the event queue
            NChantKM1.RemoveResource(ChantSpeechResource.CSREvent, 0)
        Next
    End Sub
    

Deployment Checklist

When you are ready to deploy your application, you need to ensure you have a valid license, bundle the correct Chant component libraries, and configure your installation properly on the target system.

Review the following checklist before deploying your applications:

  • You may deploy your .NET application to any system with a valid license from the Chant.
  • Copy Chant.KinectKit.dll and Chant.Shared.dll assemblies to the target system or merge them with your application using an obfuscator like .NET Reactor by Eziriz.
  • Copy NKinectKit.dll to the target system.
  • Register NKinectKit.dll as a COM library on the target system.
  • You may deploy your .NET application to any system with a valid license from the Chant.
  • Copy Chant.KinectKit.dll and Chant.Shared.dll assemblies to the target system or merge them with your application using an obfuscator like .NET Reactor by Eziriz.
  • Copy NKinectKitX64.dll to the target system.
  • Register NKinectKitX64.DLL as a COM library on the target system.

Review the following checklist before deploying your .NET Applications targeting Microsoft.Kinect with managed NAPI:

  • You may deploy your .NET application to any system with a valid license from the Chant.
  • Copy Chant.KinectKit.Kinect.dll and Chant.Shared.Speech.dll assemblies to the target system or merge them with your application using an obfuscator like .NET Reactor by Eziriz.
  • You may deploy your .NET application to any system with a valid license from the Chant.
  • Copy Chant.KinectKit.Kinect.dll and Chant.Shared.Speech.dll assemblies to the target system or merge them with your application using an obfuscator like .NET Reactor by Eziriz.

Sample Projects

.NET Windows Forms sample projects are installed at the following location:

  • My Documents\Chant KinectKit\Win32\NET WinForms\VS 2010\CSharp,
  • My Documents\Chant KinectKit\Win32\NET WinForms\VS 2010\Visual Basic,
  • My Documents\Chant KinectKit\Win32\NET WinForms\VS 2012\CSharp,
  • My Documents\Chant KinectKit\Win32\NET WinForms\VS 2012\Visual Basic.
  • My Documents\Chant KinectKit\Win64\NET WinForms\VS 2010\CSharp,
  • My Documents\Chant KinectKit\Win64\NET WinForms\VS 2010\Visual Basic,
  • My Documents\Chant KinectKit\Win64\NET WinForms\VS 2012\CSharp,
  • My Documents\Chant KinectKit\Win64\NET WinForms\VS 2012\Visual Basic.

For additional help with KinectKit, contact Chant Support via Chant Support Contacts or web.