Skip to main content

ICommandHandler.CanHandleCommand(PrintingSystemCommand, IPrintControl) Method

Indicates whether or not the specified Printing System command can be handled.

Namespace: DevExpress.XtraPrinting

Assembly: DevExpress.Printing.v21.2.Core.dll

Declaration

bool CanHandleCommand(
    PrintingSystemCommand command,
    IPrintControl printControl
)

Parameters

Name Type Description
command PrintingSystemCommand

A PrintingSystemCommand enumeration value.

printControl IPrintControl

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

Returns

Type Description
Boolean

true, if the command can be handled; otherwise, false.

Example

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.
    printTool.Report.CreateDocument(false);

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

    // Show the report's Print Preview in a dialog window.
    printTool.ShowPreviewDialog();

}

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 CanHandleCommand(PrintingSystemCommand, IPrintControl) method.

Note

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