Show a Custom Form with the WinForms Dashboard Designer
- 2 minutes to read
This topic describes how to show a custom form as the WinForms Dashboard Designer used to create and modify dashboards in WinForms XAF applications. For instance, it can be required for customizing the menu (adding custom bar items or removing certain default bar items).
- Add the new XtraForm or RibbonForm to the project.
- Add the DashboardDesigner control to the newly created form as described in the Create a Designer Application section of the Create a WinForms Designer topic.
- Add a property of the DashboardDesigner type to the custom form.
- Create a Controller in the WinForms application project (MySolution.Win). This Controller is activated in the IDashboardData Views only.
- Access the WinShowDashboardDesignerController using the Frame.GetController<ControllerType> method.
- Access the DashboardDesignerManager object using the WinShowDashboardDesignerController.DashboardDesignerManager property.
- Handle the DashboardDesignerManager.CreateCustomForm event. Create and assign a custom form to the CreateCustomFormEventArgs.Form property.
Note
A complete sample project is available at https://github.com/DevExpress-Examples/xaf-how-to-show-a-custom-form-as-the-winforms-dashboard-designer.
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Dashboards.Win;
using DevExpress.Persistent.Base;
// ...
public class CustomDashboardDesignerFormController : ObjectViewController<ObjectView, IDashboardData> {
private WinShowDashboardDesignerController showDashboardDesignerController;
protected override void OnActivated() {
base.OnActivated();
showDashboardDesignerController = Frame.GetController<WinShowDashboardDesignerController>();
if(showDashboardDesignerController != null) {
showDashboardDesignerController.DashboardDesignerManager.CreateCustomForm += Manager_CreateCustomForm;
}
}
private void Manager_CreateCustomForm(object sender, CreateCustomFormEventArgs e) {
e.Form = new CustomDashboardDesignerForm();
}
protected override void OnDeactivated() {
base.OnDeactivated();
if(showDashboardDesignerController != null) {
showDashboardDesignerController.DashboardDesignerManager.CreateCustomForm -= Manager_CreateCustomForm;
}
}
}
using DevExpress.DashboardWin;
// ...
public partial class CustomDashboardDesignerForm : DevExpress.XtraBars.Ribbon.RibbonForm {
public CustomDashboardDesignerForm() {
InitializeComponent();
}
public DashboardDesigner Designer {
get { return dashboardDesigner; }
}
}