ICommandHandler.CanHandleCommand(PrintingSystemCommand, IPrintControl) Method

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

Namespace: DevExpress.XtraPrinting

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

Declaration

bool CanHandleCommand(
    PrintingSystemCommand command,
    IPrintControl printControl
)
Function CanHandleCommand(
    command As PrintingSystemCommand,
    printControl As IPrintControl
) As Boolean

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.

Examples

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