Skip to main content
A newer version of this page is available. .

ICommandHandler Interface

If implemented by a class, provides methods for handling commands in an End-User Designer for Windows Forms.

Namespace: DevExpress.XtraReports.UserDesigner

Assembly: DevExpress.XtraReports.v20.2.Extensions.dll

NuGet Package: DevExpress.Win.Reporting

Declaration

public interface ICommandHandler

Remarks

An object implementing the ICommandHandler interface is passed to the XRDesignPanel.AddCommandHandler and XRDesignMdiController.AddCommandHandler methods as a parameter.

Every report command represents either a toolbar button and a menu item, or a context menu item, or a context link in the End-User Designer window.

To learn more, see ICommandHandler.CanHandleCommand and ICommandHandler.HandleCommand.

Example

This example demonstrates how you can prohibit your end-users from deleting a control in the End-User Designer.

using System;
using System.Windows.Forms;
using DevExpress.XtraReports.UI;
using DevExpress.XtraReports.UserDesigner;
// ...

namespace PreventDeletingControl {
    public partial class Form1 : Form {
        public Form1() {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e) {
            this.xrDesignPanel1.AddCommandHandler(new DeleteCommandHandler(this.xrDesignPanel1));
            // Load a report into the design form and show the form.
            this.xrDesignPanel1.OpenReport(new XtraReport1());
        }
    }
}

public class DeleteCommandHandler : ICommandHandler {
    XRDesignPanel panel;

    public DeleteCommandHandler(XRDesignPanel panel) {
        this.panel = panel;
    }

    public bool CanHandleCommand(ReportCommand command, ref bool useNextHandler) {
        useNextHandler = command != ReportCommand.Delete && !IsXRLabelSelected();
        return !useNextHandler;
    }

    public void HandleCommand(ReportCommand command, object[] args) {
        MessageBox.Show("Cannot delete label!");
    }

    Boolean IsXRLabelSelected() {
        object[] controls = panel.GetSelectedComponents();

        foreach (object obj in controls)
            if (obj is XRLabel)
                return true;

        return false;
    }
}
See Also