Developer Express 之 XtraReport如何显示设计窗体,打开已设计过的报表
XtraReport的设计器,其实用XRDesignFormEx就可以。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraReports.UI;
using DevExpress.XtraReports.UserDesigner;
using System.Drawing.Design;
using System.ComponentModel.Design;
namespace WFAXtraReport
{
public partial class Form1 : Form
{
XtraReport r ;//这个可以是加载之前设计好的模板
public Form1()
{
InitializeComponent();
}
private void designForm_FormClosing(object sender, FormClosingEventArgs e)
{
//在此处处理关闭设计器时的操作,主要用来自定义保存数据
//r.SaveLayout(@"C:\1.repx");
}
private void designForm_ReportStateChanged(object sender, ReportStateEventArgs e)
{
//只要报表发生改变就立即将状态设置为保存
//避免系统默认保存对话框的出现
if (e.ReportState == ReportState.Changed)
{
((XRDesignFormEx)sender).DesignPanel.ReportState = ReportState.Saved;
}
}
private void Form1_Load(object sender, EventArgs e)
{
r = new XtraReport();
//r.LoadLayout(@"C:\1.repx");
XRDesignFormEx designForm = new XRDesignFormEx();
//隐藏按钮
designForm.DesignPanel.SetCommandVisibility(new ReportCommand[]{
ReportCommand.NewReport,
ReportCommand.SaveFileAs,
ReportCommand.NewReportWizard,
ReportCommand.OpenFile
}, CommandVisibility.None);
//更改状态
designForm.ReportStateChanged += new ReportStateEventHandler(designForm_ReportStateChanged);
designForm.FormClosing += new FormClosingEventHandler(designForm_FormClosing);
// 加载报表.
designForm.OpenReport(r);
// 打开设计器
designForm.ShowDialog();
designForm.Dispose();
}
}
}
这样我们就能在加载和销毁设计窗体的时候要控制什么,你可以重载里面的数据。比如设计窗体显示有点慢,我们在开始的时候加载个等待窗体,显示出来后关闭这个