This tutorial shows how to use the LEADTOOLS Multimedia SDK to create a WinForms C# application that uses the
PlayCtrl to perform simplified playback of a video file.
|Summary||This tutorial covers how to play a video file in a WinForms C# application.|
|Completion Time||30 minutes|
|Visual Studio Project||Download tutorial project (9 KB)|
|Platform||WinForms C# Application|
|IDE||Visual Studio 2017, 2019|
|Development License||Download LEADTOOLS|
|Try it in another language|
The LEADTOOLS Multimedia Play Control contains many advanced features that simplify decoding, processing and playing back media from different sources such as files, memory buffers and network streams. The toolkit is shipped with various demos that make use of these features, such as the main Multimedia Player demo that has different editions in multiple programming languages.
Get familiar with the basic steps of creating a project by reviewing the Add References and Set a License tutorial, before working on the Playback a Video File - WinForms C# tutorial.
Start with a copy of the project created in the Add References and Set a License tutorial. If you do not have that project, follow the steps in that tutorial to create it.
This tutorial requires the following local DLLs, which are located at
Different SDK features require different references. For a complete list, refer to Multimedia Files You Must Include With Your Application.
The License unlocks the features needed for the project. It must be set before any toolkit function is called. For details, including tutorials for different platforms, refer to Setting a Runtime License.
There are two types of runtime licenses:
Adding LEADTOOLS NuGet and local references and setting a license are covered in more detail in the Add References and Set a License tutorial.
With the project created, the references added, the toolkit unlocked, and the license set, coding can begin.
In Solution Explorer, right-click on
Form1.cs and select View Code to display the code-behind of the form. Add the following statements to the
using block at the top.
// Using block at the top
Add the below code to initialize the Play Control.
// Add this global variable
private PlayCtrl _play;
In Solution Explorer, double-click
Form1.cs to display it in the Designer. Click the Events icon in the Properties Windows. Then, double-click the Load event to create an event handler.
Add the following code inside the
Form1_Load event handler.
private void Form1_Load(object sender, EventArgs e)
_play = new PlayCtrl();
_play.Dock = DockStyle.Fill;
Form1.cs in the Designer, then add a File menu with an Open menu item. To do that, open the Toolbox and double-click MenuStrip, which will add a menu to the form.
In the Designer, change the text of the menu to &File, which will underline the F in File. Then add an item to the menu and set its text to &Open. Leave the new item's name as
Open the form's Designer and double-click the
Open menu item to edit its event handler. Add the following code in it:
private void openToolStripMenuItem_Click(object sender, EventArgs e)
OpenFileDialog dlg = new OpenFileDialog();
dlg.InitialDirectory = @"C:\LEADTOOLS22\Media";
if (dlg.ShowDialog(this) == DialogResult.OK)
string inputFile = dlg.FileName;
_play.SourceFile = inputFile;
catch (Exception ex)
Run the project by pressing F5, or by selecting Debug -> Start Debugging.
If the steps were followed correctly, the application runs and allows loading and playback of any media file using the
Open dialog box.
This tutorial showed how to playback a video file using the