Skip to main content

ICommandHandler.HandleCommand(PrintingSystemCommand, Object[], IPrintControl, ref Boolean) Method

If implemented by a class, allows you to handle Printing System commands (listed in the PrintingSystemCommand enumeration).

Namespace: DevExpress.XtraPrinting

Assembly: DevExpress.Printing.v22.1.Core.dll


void HandleCommand(
    PrintingSystemCommand command,
    object[] args,
    IPrintControl printControl,
    ref bool handled


Name Type Description
command PrintingSystemCommand

A PrintingSystemCommand enumeration value.

args Object[]

An array of Object values, specifying the command arguments.

printControl IPrintControl

An object implementing the IPrintControl interface (typically, this is a PrintControl instance).

handled Boolean

true, if the command has been handled; otherwise, false.


Exceptions thrown from within a user’s handler are not allowed to bubble up to the main application thread.


This example illustrates how to override a Printing System command.

A custom command handler must implement the ICommandHandler interface. You can add it to a Printing System’s list of handlers using the PrintingSystemBase.AddCommandHandler method.

using DevExpress.XtraPrinting;
using DevExpress.XtraReports.UI;
// ...

private void button1_Click(object sender, System.EventArgs e) {
    // Create a Print Tool with an assigned report instance.
    ReportPrintTool printTool = new ReportPrintTool(new XtraReport1());

    // Generate the report's document to be able to access its Printing System.

    // Override the ExportGraphic command.
    printTool.PrintingSystem.AddCommandHandler(new ExportToImageCommandHandler());

    // Show the report's Print Preview in a dialog window.


public class ExportToImageCommandHandler : ICommandHandler {
    public virtual void HandleCommand(PrintingSystemCommand command,
    object[] args, IPrintControl printControl, ref bool handled) {
        if (!CanHandleCommand(command, printControl)) return;

        // Export the document to PNG.
        printControl.PrintingSystem.ExportToImage("C:\\Report.png", System.Drawing.Imaging.ImageFormat.Png);

        // Prevent the default exporting procedure from being called.
        handled = true;

    public virtual bool CanHandleCommand(PrintingSystemCommand command, IPrintControl printControl) {
        return command == PrintingSystemCommand.ExportGraphic;

The following code snippets (auto-collected from DevExpress Examples) contain references to the HandleCommand(PrintingSystemCommand, Object[], IPrintControl, ref Boolean) method.


The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also