Back to Devexpress

How to: Change The Visibility of Toolbar Buttons and Menu Items in the Print Preview

windowsforms-2548-controls-and-libraries-printing-exporting-examples-print-preview-how-to-change-the-visibility-of-toolbar-buttons-and-menu-items-in-the-print-preview.md

latest3.0 KB
Original Source

How to: Change The Visibility of Toolbar Buttons and Menu Items in the Print Preview

  • Nov 23, 2025
  • 2 minutes to read

This example illustrates how to change the visibility of the toolbar buttons and menu items of a print preview by using the PrintingSystemBase.SetCommandVisibility method that defines the availability of commands in print preview.

The following code hides the Watermark button from the toolbar (together with the corresponding menu item), makes the DocumentMap button and menu item visible, and then makes the ExportToCsv and ExportToTxt commands visible (in both the window’s menu, and in the toolbar).

All available commands are listed in the PrintingSystemCommand enumeration.

csharp
using DevExpress.XtraPrinting;
// ...

// Get the printing system of the DocumentViewer control.
PrintingSystemBase ps = documentViewer1.PrintingSystem;

// Hide the Watermark toolbar button, and also the Watermark menu item.
if (ps.GetCommandVisibility(PrintingSystemCommand.Watermark) != CommandVisibility.None){
   ps.SetCommandVisibility(PrintingSystemCommand.Watermark, CommandVisibility.None);
}

// Show the Document Map toolbar button and menu item.
ps.SetCommandVisibility(PrintingSystemCommand.DocumentMap, CommandVisibility.All);

// Make the "Export to Csv" and "Export to Txt" commands visible.
ps.SetCommandVisibility(new PrintingSystemCommand[] 
   {PrintingSystemCommand.ExportCsv, PrintingSystemCommand.ExportTxt}, CommandVisibility.All);
vb
Imports DevExpress.XtraPrinting
' ...

' Get the printing system of the DocumentViewer control.
Dim ps As PrintingSystemBase = documentViewer1.PrintingSystem

' Hide the Watermark toolbar button, and also the Watermark menu item.
If ps.GetCommandVisibility(PrintingSystemCommand.Watermark) <> CommandVisibility.None Then
   ps.SetCommandVisibility(PrintingSystemCommand.Watermark, CommandVisibility.None)
End If

' Show the Document Map toolbar button and menu item.
ps.SetCommandVisibility(PrintingSystemCommand.DocumentMap, CommandVisibility.All)

' Make the "Export to Csv" and "Export to Txt" commands visible.
ps.SetCommandVisibility(New PrintingSystemCommand() _
  {PrintingSystemCommand.ExportCsv, PrintingSystemCommand.ExportTxt}, CommandVisibility.All)

Tip

A complete sample project is available in the DevExpress Code Examples database at xref:1302.

See Also

How to: Customize How a Document Is Exported from the Print Preview