[Dxperience.8.*]XtraReport的设计器,其实用XRDesignFormEx就挺好。

本文介绍了一个基于 DevExpress XtraReport 的报表设计器应用实例。通过代码演示了如何自定义报表设计器的行为,例如关闭时保存布局及隐藏特定的设计按钮等。这有助于开发者更好地掌握报表设计与自定义。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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 WindowsFormsApplication2
{
    
public partial class Form1 : Form
    {
        XtraReport r ;
        
public Form1()
        {
            InitializeComponent();
        }

        
void designForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            
//在此处处理关闭设计器时的操作,主要用来自定义保存数据
            
//r.SaveLayout(@"C:\1.repx");
        }

        
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();
        }
    }
}

转载于:https://www.cnblogs.com/rock_chen/archive/2008/07/02/1234103.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值