This example demonstrates how to access the Report Designer form by handling the WinReportServiceController.DesignFormCreated event.
In this topic, it is assumed that you have an XAF application that uses the Reports V2 Module, and you have created one or more reports (see Reports V2 Module Overview).
Create a View Controller in the WinForms module project.
Override the Controller's OnActivated method, access the WinReportServiceController using the Frame.GetController<ControllerType> method and subscribe to the WinReportServiceController.DesignFormCreated event.
using System.Drawing.Design;
using DevExpress.XtraReports.UserDesigner;
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.ReportsV2.Win;
// ...
public class CustomDesignerController : ViewController {
private WinReportServiceController winReportServiceController;
protected override void OnActivated() {
base.OnActivated();
winReportServiceController = Frame.GetController<WinReportServiceController>();
if (winReportServiceController != null) {
winReportServiceController.DesignFormCreated += winReportServiceController_DesignFormCreated;
}
}
void winReportServiceController_DesignFormCreated(object sender, DesignFormEventArgs e) {
e.DesignForm.DesignMdiController.DesignPanelLoaded += DesignMdiController_DesignPanelLoaded;
}
void DesignMdiController_DesignPanelLoaded(object sender, DesignerLoadedEventArgs e) {
IToolboxService ts = (IToolboxService)e.DesignerHost.GetService(typeof(IToolboxService));
ts.AddToolboxItem(new ToolboxItem(typeof(MyControl)), "New Category");
}
}
Imports System.Drawing.Design
Imports DevExpress.XtraReports.UserDesigner
Imports DevExpress.ExpressApp
Imports DevExpress.ExpressApp.ReportsV2.Win
' ...
Public Class CustomDesignerController
Inherits ViewController
Private winReportServiceController As WinReportServiceController
Protected Overrides Sub OnActivated()
MyBase.OnActivated()
winReportServiceController = Frame.GetController(Of WinReportServiceController)()
If winReportServiceController IsNot Nothing Then
winReportServiceController.DesignFormCreated += winReportServiceController_DesignFormCreated
End If
End Sub
Private Sub winReportServiceController_DesignFormCreated( _
ByVal sender As Object, ByVal e As DesignFormEventArgs)
AddHandler e.DesignForm.DesignMdiController.DesignPanelLoaded, _
AddressOf DesignMdiController_DesignPanelLoaded
End Sub
Private Sub DesignMdiController_DesignPanelLoaded( _
ByVal sender As Object, ByVal e As DesignerLoadedEventArgs)
Dim ts As IToolboxService = CType(e.DesignerHost.GetService( _
GetType(IToolboxService)), IToolboxService)
ts.AddToolboxItem(New ToolboxItem(GetType(MyControl)), "New Category")
End Sub
End Class
In this code, a custom component is added to the Report Designer toolbar for demonstration purposes. To learn about other possible customizations, refer to the Report Designer topic.
See Also