This tutorial shows how to load the images from a DICOM Directory into the LEADTOOLS
MedicalViewer control and set the corresponding tags using the
DicomDirRetrieveClient classes in a WinForms C# application.
|Summary||This tutorial covers how to load DICOM Directory images using the MedicalViewerLoader class in a WinForms C# Application.|
|Completion Time||30 minutes|
|Visual Studio Project||Download tutorial project (10 KB)|
|Platform||Windows WinForms C# Application|
|IDE||Visual Studio 2017, 2019|
|Development License||Download LEADTOOLS|
Get familiar with the basic steps of creating a project by reviewing the Add References and Set a License tutorial, Before working on the Load DICOMDIR Images with the MedicalViewerLoader - WinForms C# tutorial.
In Visual Studio, create a new C# Windows WinForms project, and add the below necessary LEADTOOLS references.
The references needed depend upon the purpose of the project. For this project, the following DLLs are needed.
The DLLs are located at
For a complete list of which DLL files are required for your application, refer to Files to be Included 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 local references and setting a license are covered in more detail in the Add References and Set a License tutorial.
Now that the LEADTOOLS references have been added to the project and the license has been set, coding can begin.
In the Solution Explorer, double-click
Form1.cs to display the
Designer. Go to the
Form1 properties and double-click the
FormClosed event to create a
Load event handler and
FormClosed event handler for the form. This will bring up the code behind the form. Add the
using statements below to the top.
Add the below global variable to the
private MedicalViewer _medicalViewer;
Add the following code inside the
Form1_Load event handler to initialize the
private void Form1_Load(object sender, EventArgs e)
_medicalViewer = new MedicalViewer();
_medicalViewer.Dock = DockStyle.Fill;
_medicalViewer.BackColor = Color.Black;
// Start the DICOM engine
Add the following code inside the
Form1_FormClosed event handler to shutdown the
private void Form1_FormClosed(object sender, System.Windows.Forms.FormClosedEventArgs e)
Using the Solution Explorer, navigate back to the
Form1 designer. Open the Toolbox and double-click MenuStrip, which will add a menu to the form. Add a &File dropdown menu item to the new MenuStrip. Add an item to the dropdown menu and set its text to &Open. Leave the new item's name as
openToolStripMenuItem. Double-click the
Open menu item to create its event handler.
Add the following code to the
openToolStripMenuItem_Click event handler to load a DICOM Directory to the
private void openToolStripMenuItem_Click(object sender, EventArgs e)
OpenFileDialog dlg = new OpenFileDialog();
if (dlg.ShowDialog() == DialogResult.OK)
// Create Dicom DIR Retrieve Client
DicomDirRetrieveClient dicomDirClient = new DicomDirRetrieveClient(null, dlg.FileName);
// Create Medical Viewer Loader associating with Dicom Dir client
MedicalViewerLoader loader = new MedicalViewerLoader(dicomDirClient);
// Initialize Loader
loader.ViewerControl = _medicalViewer; // Tell loader to load images into our viewer
loader.Layout.Auto = true;
loader.LazyLoading = true; // This will cause the loader to load the images for displayed sub-cells only
loader.ViewerPreLoadedImages = 1; // This will allow the loader to load 1 image after and before the displayed sub-cell for fast scrolling
string studyInstanceUID = string.Empty; // Can specify a Study Instance UID or leave blank
string seriesInstanceUID = string.Empty; // Can specify a Series Instance UID or leave blank
this.Cursor = Cursors.WaitCursor;
if (!loader.LoadSeries(studyInstanceUID, seriesInstanceUID)) // Load and parse the DICOM Dir file
MessageBox.Show("Unable to load series!");
catch (Exception ex)
this.Cursor = Cursors.Arrow;
Run the project by pressing F5, or by selecting Debug -> Start Debugging.
If the steps were followed correctly, the application runs and the form should appear. To test, follow the steps below:
Click on File -> Open to bring up the OpenFileDialog.
Select the DICOM Directory you wish to view and select OK.
Use the scrollbars on the side of the viewer to view the images in the series.
This tutorial showed how to load the images from a DICOM Directory file-set, set and display the corresponding tags in the Medical Viewer. In addition, it showed how to use the