注意 |
---|
重要说明: .NET Client Profile Framework 不支持此功能。 要在最终用户的机器上使用此功能,则必须安装完整的 .NET Framework。 更多信息,请参阅 Windows 窗体部署 文档中的 关于 .NET Framework 4.0 Client Profile 的重要说明 小节。 |
这个示例展示了如何把 自定义控件 (XRControl 的子类) 添加到最终用户设计器的 工具箱 中,并使控件只能用于特定的报表实例。
要这样做,需要接管 XtraReport.DesignerLoaded 事件,然后把所需的项添加到工具箱中。
或者,要使控件只能用于 MDI 设计器中的所有已打开的报表,则接管 XRDesignMdiController.DesignPanelLoaded 事件。
要获得关于在 XtraReports 中使用 System.Windows.Forms 控件的信息,请参阅 标准的 Windows 窗体控件。
C# | 复制代码 |
---|---|
using System.Drawing.Design; using DevExpress.XtraReports.UI; using DevExpress.XtraReports.UserDesigner; // ... private void button1_Click(object sender, EventArgs e) { // Create a new End-User Designer. XRDesignForm designForm = new XRDesignForm(); // Create a report instance. XtraReport1 report = new XtraReport1(); // Handle the event when the report is loaded into the End-User Designer. report.DesignerLoaded += new DesignerLoadedEventHandler(report_DesignerLoaded); // Load the report into the designer. designForm.OpenReport(report); // Show the End-User Designer window. designForm.Show(); } private void report_DesignerLoaded(object sender, DesignerLoadedEventArgs e) { IToolboxService ts = (IToolboxService)e.DesignerHost.GetService(typeof(IToolboxService)); // Add a custom control. ts.AddToolboxItem(new ToolboxItem(typeof(MyControl))); } // A custom control. public class MyControl : XRControl { // ... } |
Visual Basic | 复制代码 |
---|---|
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 a new End-User Designer. Dim designForm As New XRDesignForm() ' Create a report instance. Dim report As New XtraReport1() ' Handle the event when the report is loaded into the End-User Designer. AddHandler report.DesignerLoaded, AddressOf report_DesignerLoaded ' Load the report into the designer. designForm.OpenReport(report) ' Show the End-User Designer window. designForm.Show() End Sub Private Sub report_DesignerLoaded(ByVal sender As Object, _ ByVal e As DesignerLoadedEventArgs) Dim ts As IToolboxService = _ CType(e.DesignerHost.GetService(GetType(IToolboxService)), IToolboxService) ' Add a custom control. ts.AddToolboxItem(New ToolboxItem(GetType(MyControl))) End Sub ' A custom control. Public Class MyControl Inherits XRControl ' ... End Class |
Show Me |
---|
在 DevExpress Code Central 数据库中可以找到完整的示例项目,网址是 http://www.devexpress.com/example=E1929。 取决于目标平台类型 (ASP.NET、WinForms 等),可以在线运行本示例,或者下载自动可执行的示例。 |