How Can I Use the Windows Print Dialog to Configure a Printer in LabVIEW?

Updated Jan 17, 2023



  • LabVIEW Full

I would like to use the Windows dialog to configure the printer settings for printing documents from LabVIEW. How can I access this dialog without having to make my own?

Microsoft's .NET Framework provides access to several operating system dialogs which can be accessed through LabVIEW using the .NET nodes from the Connectivity palette. You can use the properties and methods of the .NET Print Dialog object to set these preferences for each document you wish to print.
  1. Right-click on the block diagram to bring up the Functions palette and navigate to Connectivity».NET. Choose the .NET Constructor node and place it on the block diagram.
  2. In the configuration dialog that appears, select Assembly System.Windows.Forms( Expand the System.Windows.Forms Object and choose PrintDialog. Click OK.
  3. Right-click the new reference terminal on the constructor node and choose Create»Method for System.Windows.Forms.PrintDialog Class»ShowDialog().
  4. Wire the new reference from the constructor node to reference on the .NET invoke node. This will bring up the Windows Print Dialog which lets you configure the settings for the printer.
Follow the Related Link to the NI Community  for an example program demonstrating this. The example uses the showDialog(IWin32Window owner) method, a variaton of the ShowDialog method. This allows you to specify a window as the owner of the dialog. To get an IWin32Window reference, a C# DLL and wrapper VIs are used. 

The GetPrinterSettings VI demonstrates how to access different properties of the printer settings stored in the dialog. It allows you to access the page orientation, margins, printer name, and number of copies to print.

The Print Front Panel VI takes a reference to a VI and waits for the user to close the Print Dialog. If the OK button is pressed, a LabVIEW report containing an image of the VI's front panel and prints the report to the designated printer with settings from the dialog. If the dialog is closed without using the OK button, nothing is printed.

Note: The VI reference passed into Print Front Panel must have its front panel open because the WindowWrapper DLL looks at the VI's Title Bar to make that VI the owner of the dialog.