xtrareports-7546-desktop-reporting-winforms-reporting-end-user-report-designer-for-winforms-api-and-customization-add-custom-control-to-the-end-user-report-designers-toolbox.md
This document describes how to create a WinForms project with a custom control and add the control to the WinForms End-User Report Designer Toolbox.
View Example: Add a Custom Control to the End-User Report Designer Toolbox (WinForms)
Add an .svg icon named NumericLabel.svg to the project and set the icon’s Build Action property to Embedded Resource.
Apply the ToolboxSvgImage attribute to the custom control:
using DevExpress.Utils.Design;
//..
[ToolboxSvgImage("WinFormsApp_CustomNumericLabel.NumericLabel.svg, WinFormsApp_CustomNumericLabel")]
public class NumericLabel : XRLabel { ... }
Imports DevExpress.Utils.Design
'..
<ToolboxSvgImage("WinFormsApp_CustomNumericLabel.NumericLabel.svg, WinFormsApp_CustomNumericLabel")>
Public Class NumericLabel
Inherits XRLabel
Private ...}
The ToolboxBitmap attribute allows you to specify a 16x16 bitmap icon for a custom control. The icon is displayed in the Report Explorer and the Toolbox. In the Toolbox , the icon is scaled to 24x24 for the standard Report Designer and 32x32 for the ribbon-based Report Designer. You can use ToolboxBitmap24Attribute and ToolboxBitmap32Attribute to specify icons of the 24x24 and 32x32 sizes.
using DevExpress.Utils.Design;
using System.Drawing;
//...
namespace WinFormsApp_CustomNumericLabel {
[ToolboxBitmap(typeof(NumericLabel), "NumericLabel.png")]
[ToolboxBitmap24Attribute("WinFormsApp_CustomNumericLabel.NumericLabel24x24.png, WinFormsApp_CustomNumericLabel")]
public class NumericLabel : XRLabel { ... }
}
Imports DevExpress.Utils.Design
Imports System.Drawing
'...
Namespace WinFormsApp_CustomNumericLabel
<ToolboxBitmap(GetType(NumericLabel), "NumericLabel.png"), ToolboxBitmap24Attribute("WinFormsApp_CustomNumericLabel.NumericLabel2.png, WinFormsApp_CustomNumericLabel")>
Public Class NumericLabel
Inherits XRLabel
Private ...}
End Class
Handle the XRDesignMdiController.DesignPanelLoaded event to add the custom control to the Toolbox:
using DevExpress.XtraReports.UI;
using DevExpress.XtraReports.UserDesigner;
using System;
using System.Drawing.Design;
using System.Windows.Forms;
// ...
void ShowDesignerWithCustomControl()
{
// Creates a Design Tool instance with the specified report instance.
ReportDesignTool designTool = new ReportDesignTool(new XtraReport1());
IDesignForm designForm = designTool.DesignForm;
designForm.DesignMdiController.DesignPanelLoaded += DesignMdiController_DesignPanelLoaded;
designTool.ShowDesignerDialog();
}
void DesignMdiController_DesignPanelLoaded(object sender, DesignerLoadedEventArgs e) {
IToolboxService toolboxService =
(IToolboxService)e.DesignerHost.GetService(typeof(IToolboxService));
// Removes the XRLabel toolbox item.
toolboxService.RemoveToolboxItem(
GetToolBoxControl(toolboxService, "DevExpress.XtraReports.UI.XRLabel"));
// Creates a new toolbox item for the custom control.
ToolboxItem numericLabelItem = new ToolboxItem(typeof(NumericLabel))
{
// Specifies the name in the toolbox.
DisplayName = "Numeric Label"
};
// Adds the new control to the toolbox.
toolboxService.AddToolboxItem(numericLabelItem);
}
ToolboxItem GetToolBoxControl(IToolboxService toolboxService, string name) {
foreach (ToolboxItem item in toolboxService.GetToolboxItems()) {
if (item.TypeName == name) { return item; };
}
return null;
}
Imports DevExpress.XtraReports.UI
Imports DevExpress.XtraReports.UserDesigner
Imports System
Imports System.Drawing.Design
Imports System.Windows.Forms
' ...
Private Sub ShowDesignerWithCustomControl()
' Creates a Design Tool instance with the specified report instance.
Dim designTool As New ReportDesignTool(New XtraReport1())
Dim designForm As IDesignForm = designTool.DesignForm
AddHandler designForm.DesignMdiController.DesignPanelLoaded, AddressOf DesignMdiController_DesignPanelLoaded
designTool.ShowDesigner()
End Sub
Private Sub DesignMdiController_DesignPanelLoaded(ByVal sender As Object, ByVal e As DesignerLoadedEventArgs)
Dim toolboxService As IToolboxService = DirectCast(e.DesignerHost.GetService(GetType(IToolboxService)), IToolboxService)
' Removes the XRLabel toolbox item.
toolboxService.RemoveToolboxItem(GetToolBoxControl(toolboxService, "DevExpress.XtraReports.UI.XRLabel"))
' Creates a new toolbox item for the custom control.
Dim numericLabelItem As New ToolboxItem(GetType(NumericLabel)) With {.DisplayName = "Numeric Label"}
' Adds the new control to the toolbox.
toolboxService.AddToolboxItem(numericLabelItem)
End Sub
Private Function GetToolBoxControl(ByVal toolboxService As IToolboxService, ByVal name As String) As ToolboxItem
For Each item As ToolboxItem In toolboxService.GetToolboxItems()
If item.TypeName = name Then
Return item
End If
Next item
Return Nothing
End Function
Tip
The added control is available for any report opened in the Report Designer. You can also make a custom control available for specific reports only.
See Also