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.v20.2.Core.dll


void HandleCommand(
    PrintingSystemCommand command,
    object[] args,
    IPrintControl printControl,
    ref bool handled
Sub HandleCommand(
    command As PrintingSystemCommand,
    args As Object(),
    printControl As IPrintControl,
    ByRef handled As Boolean


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;
See Also