Note注意

重要说明: .NET Client Profile Framework 不支持此功能。 要在最终用户的机器上使用此功能,则必须安装完整的 .NET Framework。 更多信息,请参阅 Windows 窗体部署 文档中的 关于 .NET Framework 4.0 Client Profile 的重要说明 小节。

这个示例展示了如何把自定义控件添加到最终用户设计器的 工具箱 中 。

要这样做,则接管 XRDesignMdiController.DesignPanelLoaded 事件处理程序,然后把所需的项添加到工具箱中。

要使本示例能正确工作,则 XtraReport1 子类(派生于 XtraReport 类) 应该存在于示例应用程序中。

C#CopyCode image复制代码
using System;
using System.Windows.Forms;
using System.Drawing.Design;
using DevExpress.XtraReports.UI;
using DevExpress.XtraReports.UserDesigner;
// ...

private void button1_Click(object sender, EventArgs e) {
    // Create an End-User Designer form.
    XRDesignForm designForm = new XRDesignForm();

    // Handle the DesignPanelLoaded event.
    designForm.DesignMdiController.DesignPanelLoaded +=
        new DesignerLoadedEventHandler(DesignMdiController_DesignPanelLoaded);

    // Load a report into the Designer.
    designForm.OpenReport(new XtraReport1());

    // Show the End-User Designer form, modally.
    designForm.ShowDialog();
}

void DesignMdiController_DesignPanelLoaded(object sender, DesignerLoadedEventArgs e) {
    // Get the Toolbox service from the Designer host.
    IToolboxService ts =
        (IToolboxService)e.DesignerHost.GetService(typeof(IToolboxService));

    // Add a new category to the Toolbox,
    // and place a custom control into it.
    ts.AddToolboxItem(new ToolboxItem(typeof(MyControl)), "New Category");
}

// A custom control.
public class MyControl : XRControl {
    // ...
}
Visual BasicCopyCode image复制代码
Imports System
Imports System.Windows.Forms
Imports System.Drawing.Design
Imports DevExpress.XtraReports.UI
Imports DevExpress.XtraReports.UserDesigner
' ...

Private Sub button1_Click(ByVal sender As Object, _ 
ByVal e As EventArgs) Handles button1.Click
    ' Create an End-User Designer form.
    Dim designForm As New XRDesignForm()

    ' Handle the DesignPanelLoaded event.
    AddHandler designForm.DesignMdiController.DesignPanelLoaded, _ 
        AddressOf DesignMdiController_DesignPanelLoaded

    ' Load a report into the Designer.
    designForm.OpenReport(New XtraReport1())

    ' Show the End-User Designer form, modally.
    designForm.ShowDialog()
End Sub

Private Sub DesignMdiController_DesignPanelLoaded(ByVal sender As Object, _ 
ByVal e As DesignerLoadedEventArgs)
    ' Get the Toolbox service from the Designer host.
    Dim ts As IToolboxService = _ 
        CType(e.DesignerHost.GetService(GetType(IToolboxService)), IToolboxService)

    ' Add a new category to the Toolbox,
    ' and place a custom control into it.
    ts.AddToolboxItem(New ToolboxItem(GetType(MyControl)), "New Category")
End Sub

' A custom control.
Public Class MyControl
    Inherits XRControl
    ' ...
End Class

注意,当控件被添加、而没有指定类别时,它被放置在标准控件中。

或者,如果指定了类别,那么自定义控件将被独立显示。

Expand image参阅