xtrareports-devexpress-dot-xtrareports-dot-userdesigner-c5da69da.md
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.v25.2.Extensions.dll
NuGet Package : DevExpress.Win.Reporting
public interface ICommandHandler
Public Interface ICommandHandler
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.
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;
}
}
Imports Microsoft.VisualBasic
Imports System
Imports System.Windows.Forms
Imports DevExpress.XtraReports.UI
Imports DevExpress.XtraReports.UserDesigner
' ...
Namespace PreventDeletingControl
Partial Public Class Form1
Inherits Form
Public Sub New()
InitializeComponent()
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
Me.xrDesignPanel1.AddCommandHandler(New DeleteCommandHandler(Me.xrDesignPanel1))
' Load a report into the design form and show the form.
Me.xrDesignPanel1.OpenReport(New XtraReport1())
End Sub
End Class
End Namespace
Public Class DeleteCommandHandler
Implements ICommandHandler
Private panel As XRDesignPanel
Public Sub New(ByVal panel As XRDesignPanel)
Me.panel = panel
End Sub
Public Function CanHandleCommand(ByVal command As ReportCommand, _
ByRef useNextHandler As Boolean) As Boolean Implements ICommandHandler.CanHandleCommand
useNextHandler = command <> ReportCommand.Delete AndAlso Not IsXRLabelSelected()
Return Not useNextHandler
End Function
Public Sub HandleCommand(ByVal command As ReportCommand, _
ByVal args() As Object) Implements ICommandHandler.HandleCommand
MessageBox.Show("Cannot delete label!")
End Sub
Private Function IsXRLabelSelected() As Boolean
Dim controls() As Object = panel.GetSelectedComponents()
For Each obj As Object In controls
If TypeOf obj Is XRLabel Then
Return True
End If
Next obj
Return False
End Function
End Class
See Also