Load DICOMDIR Images with the MedicalViewerLoader - WinForms C#

This tutorial shows how to load the images from a DICOM Directory into the LEADTOOLS MedicalViewer control and set the corresponding tags using the MedicalViewerLoader and DicomDirRetrieveClient classes in a WinForms C# application.

Overview  
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 2019, 2022
Development License Download LEADTOOLS

Required Knowledge

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.

Create the Project and Add LEADTOOLS References

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.

The references needed depend upon the purpose of the project. For this project, the following DLLs are needed.

The DLLs are located at <INSTALL_DIR>\LEADTOOLS23\Bin\Dotnet4\x64:

For a complete list of which DLL files are required for your application, refer to Files to be Included With Your Application.

Set the License File

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:

Note

Adding LEADTOOLS local references and setting a license are covered in more detail in the Add References and Set a License tutorial.

Initialize the Medical Viewer and DICOM Engine

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 Load and 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.

C#
using System; 
using System.IO; 
using System.Windows.Forms; 
using System.Drawing; 
using Leadtools; 
using Leadtools.MedicalViewer; 
using Leadtools.Medical.Workstation.Loader; 
using Leadtools.Medical.Workstation.Client.Local; 

Add the below global variable to the Form1 class.

C#
private MedicalViewer _medicalViewer; 

Add the following code inside the Form1_Load event handler to initialize the MedicalViewer.

C#
private void Form1_Load(object sender, EventArgs e) 
{ 
   _medicalViewer = new MedicalViewer(); 
   _medicalViewer.Dock = DockStyle.Fill; 
   _medicalViewer.BackColor = Color.Black; 
   Controls.Add(_medicalViewer); 
   _medicalViewer.BringToFront(); 
 
   // Start the DICOM engine 
   Leadtools.Dicom.DicomEngine.Startup(); 
} 

Add the following code inside the Form1_FormClosed event handler to shutdown the DicomEngine.

C#
private void Form1_FormClosed(object sender, System.Windows.Forms.FormClosedEventArgs e) 
{ 
   Leadtools.Dicom.DicomEngine.Shutdown(); 
} 

Add the Load DICOM Directory Code

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 MedicalViewer.

C#
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 
 
      try 
      { 
         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) 
      { 
         MessageBox.Show(ex.Message); 
      } 
      finally 
      { 
         this.Cursor = Cursors.Arrow; 
      } 
   } 
} 

Run the Project

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:

  1. Click on File -> Open to bring up the OpenFileDialog.

  2. Select the DICOM Directory you wish to view and select OK.

  3. Use the scrollbars on the side of the viewer to view the images in the series.

    Screenshot of a DICOMDIR loaded in the viewer.

Wrap-up

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 MedicalViewerLoader and DicomDirRetrieveClient classes.

See Also

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


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