没错,ActiveReports Pro 提供了一个Designer控件,也提供了一个EndUserDesigner程序,但功能不近人意,那如何为用户提供一个专业的,易用的 EndUserDesigner呢?
程序名:ReportDesigner 以下简称:RD2
功能特色:
一,友好的Ribbon界面;
二,支持两种设计模式:报表(Report),模板文件(TemplateFile):
1, ReportMode: 实现对程序内置的报表进行修改;
2, TemplateFileMode: 通过能够独立运行的设计器对.rpx,.design的报表格式进行创建/修改;
3, 通过双击.rdf文件直接打开报表预览窗口。
三,实现记住最近使用的设计文档(仅TemplateFile模式),支持按"使用时间;修改时间;扩展名;文件名"进行排序,支持固定索引;
四,支持内建的数据源DataSet对象和更多标准控件到报表设计器;
五,支持类似于Photoshop的快照功能;
六,丰富,直观的报表设置途径。
待改善:
一,单一的设计窗口,暂不支持多窗口设计(MultiWindow);
二,目前快照功能只支持最多三个快照对象(可实现通过设置来决定最多能创建多少个快照对象)。
第三方核心组件:
ActiveReports 3.0 Pro SP2;
DevExpress v8.2.
程序入口:
启动界面:
设计器主界面:
功能实现讲解:
实现设计模式:
报表模式于模板模式不同的是:
1,不能新增报表,但允许导入模式文件;
2,主窗体以Modal方式显示,返回DialogResult值,只能返回DialogResult.OK,才表示需要重新加载报表;
3,原来的“保存”文件成了“保存并关闭”。
4,从RecentMRU列表打开模式文件,将开启一个新的RD2进程来并以TemplateFile模式打开。
实现记住最近使用的设计文档:(RecentDesignDocumentsMRU):
类似于Office System 的文档使用历史记录。
设置窗口:
核心实现:
主窗体调用:
实现排序和更新列表:
绘制边框颜色块:
丰富的打印设置:
相关设置捷径:
相关代码:
基类:
举例打印机设置:
完.
程序名:ReportDesigner 以下简称:RD2
功能特色:
一,友好的Ribbon界面;
二,支持两种设计模式:报表(Report),模板文件(TemplateFile):
1, ReportMode: 实现对程序内置的报表进行修改;
2, TemplateFileMode: 通过能够独立运行的设计器对.rpx,.design的报表格式进行创建/修改;
3, 通过双击.rdf文件直接打开报表预览窗口。
三,实现记住最近使用的设计文档(仅TemplateFile模式),支持按"使用时间;修改时间;扩展名;文件名"进行排序,支持固定索引;
四,支持内建的数据源DataSet对象和更多标准控件到报表设计器;
五,支持类似于Photoshop的快照功能;
六,丰富,直观的报表设置途径。
待改善:
一,单一的设计窗口,暂不支持多窗口设计(MultiWindow);
二,目前快照功能只支持最多三个快照对象(可实现通过设置来决定最多能创建多少个快照对象)。
第三方核心组件:
ActiveReports 3.0 Pro SP2;
DevExpress v8.2.
程序入口:
- [STAThread]
- static void Main(string[] args)
- {
- Application.EnableVisualStyles();
- Application.SetCompatibleTextRenderingDefault(false);
- string customInfo;
- string fileName;
- bool reportViewFlag = false;
- if (args.Length > 0)
- {
- fileName = args[0];
- string Extension = System.IO.Path.GetExtension(args[0]).ToLower();
- if (Extension == ".rdf")
- {
- reportViewFlag = true;
- customInfo = "正在打开报表预览:" + args[0] + "...";
- }
- else
- customInfo = "正在设计文档:" + args[0] + "...";
- }
- else
- {
- customInfo = "正在创建一个空白设计...";
- fileName = string.Empty;
- }
- if (Common.frmSplash.SplashDone(typeof(ReportDesignerRibbonForm), CIMS.Common.frmSplash.SplashTypeEnum.ReportDesigner, customInfo) == DialogResult.OK)
- {
- if (reportViewFlag)
- {
- ReportViewerForm Viewer = new ReportViewerForm(true);
- Viewer.ShowInTaskbar = true;
- Viewer.Text = string.Format("报表预览器 - [{0}]", fileName);
- Viewer.Activate();
- Viewer.ReportViewer.ExportToFileClick += ExportToFile_Click;
- Viewer.ReportViewer.Document.InProgress = true;
- Viewer.ReportViewer.Document.Load(fileName);
- CIMS.Document.ReportSettings docSet = new CIMS.Document.ReportSettings();
- Viewer.ReportViewer.Document.Printer.PrinterName = docSet.PrinterName;
- CIMS.Document.ReportSettings.PageDirectionEnum pd = Document.BorderStyle.PageDirectionEnum.Horizontal;
- if (Viewer.ReportViewer.Document.Printer.Landscape == false)
- pd = Document.BorderStyle.PageDirectionEnum.Vertical;
- //Viewer.ReportViewer.Document.Printer.DefaultPageSettings.Margins = docSet.get_Margins(pd);
- Application.Run(Viewer);
- }
- else
- {
- DevExpress.UserSkins.OfficeSkins.Register();
- DevExpress.UserSkins.BonusSkins.Register();
- DevExpress.Utils.AppearanceObject.ControlAppearance.Font = Common.Common.DefaultFont;
- DevExpress.Utils.AppearanceObject.DefaultFont = Common.Common.DefaultFont;
- DevExpress.Utils.AppearanceObject.EmptyAppearance.Font = Common.Common.DefaultFont;
- DevExpress.Skins.SkinManager.EnableFormSkinsIfNotVista();
- CIMS.Common.Language.InitLanguage();//必须在LocalizationResUtils.InitLanguage()之前调用
- CIMS.Controls.LocalizationResUtils.InitLanguage();
- if (CIMS.Common.Language.Active != CIMS.Common.Language.LanguageEnum.English)
- {
- DevExpress.XtraNavBar.NavBarLocalizer.Active = new Resources.CustomNavBarLocalizer();
- }
- CIMS.Report.Designer.ReportDesignerRibbonForm mainForm = new ReportDesignerRibbonForm(fileName);
- //Common.InfoProvider.SendInfo += new CIMS.Common.InfoProvider.SendProcessInfoHandler(mainForm.SetProcessInfo);
- Application.Run(mainForm);
- }
- }
- }
设计器主界面:
功能实现讲解:
实现设计模式:
报表模式于模板模式不同的是:
1,不能新增报表,但允许导入模式文件;
2,主窗体以Modal方式显示,返回DialogResult值,只能返回DialogResult.OK,才表示需要重新加载报表;
3,原来的“保存”文件成了“保存并关闭”。
4,从RecentMRU列表打开模式文件,将开启一个新的RD2进程来并以TemplateFile模式打开。
- public enum DesignerModeEnum
- {
- /// <summary>
- /// RPX文件设计模式
- /// </summary>
- File = 0,
- /// <summary>
- /// 报表设计模式
- /// </summary>
- Report = 1
- }
- /// <summary>
- /// 获取设计器的设计模式(RPX文件还是报表对象)
- /// </summary>
- public DesignerModeEnum DesignerMode
- {
- get { return string.IsNullOrEmpty(FileName) ? DesignerModeEnum.Report : DesignerModeEnum.File; }
- }
- /// <summary>
- /// 获取报表设计状态是否已更改(需要提示保存)
- /// </summary>
- public bool DesignChanged
- {
- get { return Designer.IsDirty; }
- set
- {
- if (Designer.IsDirty == value) return;
- Designer.IsDirty = value;
- this.SetDesignerModeText();
- }
- }
- /// <summary>
- /// 获取或设置设计的RPX报表文件
- /// </summary>
- public string FileName
- {
- get { return m_fileName; }
- set
- {
- if (m_fileName == value) return;
- m_fileName = value;
- this.SetDesignerMode();
- }
- }
- /// <summary>
- /// 设置报表设计模式(RPX文件还是报表对象)
- /// </summary>
- protected void SetDesignerMode()
- {
- this.Designer.UndoManager.Clear();
- this.SetDesignerModeText();
- if (this.DesignerMode == DesignerModeEnum.Report)
- {
- this.barReportNew.Enabled = false;
- this.barReportOpen.Enabled = false;
- this.barReportSave.Caption = "保存并预览";
- this.barReportSave.Hint = "保存设计并在关闭设计器后重新加载报表数据到预览窗口.";
- }
- else
- {
- this.barReportNew.Enabled = true;
- this.barReportOpen.Enabled = true;
- this.barReportSave.Caption = "保存";
- this.barReportSave.Hint = "保存设计文件 '" + this.FileName + "'";
- }
- this.barReportNewPopup.Enabled = this.barReportNew.Enabled;
- this.barReportSavePopup.Caption = this.barReportSave.Caption;
- this.barReportSavePopup.Hint = this.barReportSave.Hint;
- }
- protected void SetDesignerModeText()
- {
- string text = (this.DesignerMode == DesignerModeEnum.File ? this.FileName : this.DocumentName);
- if (this.DesignChanged) text += " *";
- text += " - 报表设计器 V2";
- this.Text = text;
- }
实现记住最近使用的设计文档:(RecentDesignDocumentsMRU):
类似于Office System 的文档使用历史记录。
设置窗口:
核心实现:
- public enum RecentSortModeEnum
- {
- /// <summary>
- /// 按索引(最近打开时间)
- /// </summary>
- ByIndex = 0,
- /// <summary>
- /// 按最近访问时间
- /// </summary>
- ByLastAccessDateTime = 1,
- /// <summary>
- /// 按最近修改时间
- /// </summary>
- ByLastWriteDateTime = 2,
- /// <summary>
- /// 按文件名
- /// </summary>
- ByFileName=3,
- /// <summary>
- /// 获取设计文件的扩展名(不含.)
- /// </summary>
- ByExtension=4
- }
- protected string mrfFileName = "RibbonMRURecentFiles.ini";
- protected string MURFieName { get { return Application.StartupPath + "//Settings//" + mrfFileName; } }
- private const char MURSPLITCHAR = ';';
- void InitMostRecentFiles()
- {
- string settingsName = MURFieName;
- if (System.IO.File.Exists(settingsName) == false) return;
- System.IO.StreamReader sr = null;
- try
- {
- sr = System.IO.File.OpenText(settingsName);
- for (string s = sr.ReadLine(); s != null; s = sr.ReadLine())//每行一个,保存格式:[FileFullName];[Index];[IsIndexFixed]
- {
- string[] args = s.Split(MURSPLITCHAR);
- this.RecentFilesMRU.Add(args[0], Convert.ToInt32(args[1]), Convert.ToBoolean(args[2]));
- }
- }
- //catch (Exception err) { Common.ExceptionMessenger.OnThrowError("无法从配置文件中获取最近的设计文件列表!", err); }
- finally
- {
- if (sr != null) sr.Close();
- this.RecentFilesMRU.IsChanged = false;
- }
- }
- void SaveMostRecentFiles()
- {
- if (this.RecentFilesMRU.IsChanged == false) return;
- System.IO.StreamWriter sw = null;
- string settingFile = MURFieName;
- try
- {
- sw = System.IO.File.CreateText(settingFile);
- for (int i = RecentFilesMRU.Count - 1; i >= 0; i--)
- {
- string fileFullName = RecentFilesMRU[i].ToString();
- sw.WriteLine(string.Format("{1}{0}{2}{0}{3}", MURSPLITCHAR, fileFullName, i, this.RecentFilesMRU.GetLabelChecked(fileFullName)));
- }
- sw.Close();
- }
- catch (Exception err) { Common.ExceptionMessenger.OnThrowError("无法保存最近的设计文件列表到配置文件:'" + settingFile + "'!", err); }
- finally
- {
- if (sw != null) sw.Close();
- }
- }
- void AddToMostRecentFile()
- {
- this.RecentFilesMRU.InsertElement(this.FileName);
- }
- void OnLabelClicked(object sender, EventArgs e)
- {
- RecentDesignItem selectedItem = (RecentDesignItem)sender;
- if (System.IO.File.Exists(selectedItem.FullName) == false)
- {
- if (MessageBox.Show("对不起,设计文档 " + Common.Common.GetMasks(selectedItem.FullName) + " 已经改名或删除!要从列表中移除对它的引用吗?", "打开设计文档", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK) RecentFilesMRU.Remove(selectedItem);
- return;
- }
- if (this.DesignerMode == DesignerModeEnum.Report)
- {
- applicationMenu1.HidePopup();
- this.Refresh();
- if (MessageBox.Show("对不起!目前为报表设计模式(非文件),您是否希望在新进程中打开它?", this.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes)
- {
- System.Diagnostics.Process.Start(Common.Apps.GetAppFilePath(CIMS.Common.frmSplash.SplashTypeEnum.ReportDesigner), selectedItem.FullName);
- }
- return;
- }
- bool result = this.OpenReportFile(selectedItem.FullName);
- if (result)
- {
- applicationMenu1.HidePopup();
- this.Refresh();
- this.FileName = selectedItem.FullName;
- this.AddToMostRecentFile();
- }
- }
- public event EventHandler RecentDesignItemsSorted=null;
- protected bool m_updated = true;
- public void BeginUpdate() { m_updated = false; }
- public void EndUpdate()
- {
- m_updated = true;
- this.Update();
- }
- /// <summary>
- /// 获取或设置列表的排序模式(并立即排序)
- /// </summary>
- public RecentDesignItemSorter.RecentSortModeEnum SortMode
- {
- get { return m_sortMode; }
- set {
- if (m_sortMode == value) return;
- m_sortMode = value;
- this.Update();
- }
- }
- /// <summary>
- /// 获取或设置列表排序方式(并立即排序)
- /// </summary>
- public SortOrder SortOrder
- {
- get { return m_sortOrder; }
- set
- {
- if (m_sortOrder == value) return;
- m_sortOrder = value;
- this.Update();
- }
- }
- public void Update()
- {
- if (m_updated == false) return;
- this.Sort();
- this.OnUpdateRecentDesignItems(EventArgs.Empty);
- m_updated = true;
- }
- public override void Sort()
- {
- //以后可以由用户控制
- base.Sort(new RecentDesignItemSorter(this.SortMode, this.SortOrder));
- if (RecentDesignItemsSorted != null) RecentDesignItemsSorted(this, EventArgs.Empty);
- }
- /// <summary>
- /// 对项目重新排序
- /// </summary>
- /// <param name="e"></param>
- protected void OnUpdateRecentDesignItems(EventArgs e)
- {
- container.Controls.Clear();
- foreach (RecentDesignItem item in this)
- {
- this.OnCreateToMRU(item,item.IndexFixed);
- }
- }
RecentDesignItemSorter 暂不公开代码.
快照功能:
允许创建或恢复报表设计状态(原理是将报表暂存到MemoryStream,然后用LoadReport(stream)方法载入). 功能待改善.
快照管理窗口,实现快照的创建,删除,选择等操作:
- public class ReportSnapItem : IDisposable
- {
- protected System.IO.MemoryStream m_reportSnap = null;
- protected DateTime m_createdTime = DateTime.MinValue;
- protected int m_controlsCount = 0;
- protected int m_index = 0;
- public ReportSanpItem(int index) { m_index = index; }
- public ReportSanpItem(DataDynamics.ActiveReports.Design.Designer designer)
- {
- this.ToSanp(designer);
- }
- #region Methods
- /// <summary>
- /// 创建报表快照到MemoryStream
- /// </summary>
- /// <param name="report">报表</param>
- public bool ToSanp(DataDynamics.ActiveReports.Design.Designer designer)
- {
- if (IsCreated)
- {
- if (MessageBox.Show("快照已存在,您真的要替换这份快照吗?/n快照名:" + string.Format("{0};控件数量:{1};创建时间:{2}", this.ToString(), this.ControlsCount, this.CreatedTime), "保存快照", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.Cancel) return false;
- this.ClearSanp();
- }
- m_reportSanp = new MemoryStream();
- designer.Report.SaveLayout(m_reportSanp);
- m_reportSanp.Position = 0;
- m_createdTime = DateTime.Now;
- foreach(DataDynamics.ActiveReports.Section section in designer.Report.Sections)
- {
- m_controlsCount += section.Controls.Count;
- }
- CIMS.Common.InfoProvider.OnInfo(string.Format("'{0}' 已创建!如果不需要请及时清除它。",ToString()),'m');
- return true;
- }
- public bool ResumeSanp(DataDynamics.ActiveReports.Design.Designer designer)
- {
- if (IsCreated == false) return false;
- foreach (DataDynamics.ActiveReports.Section section in designer.Report.Sections)
- {
- section.Controls.Clear();
- }
- try
- {
- designer.NewReport();//必须先创建一个新的报表设计!AR 的一个BUG
- designer.LoadReport(this.ReportSanp);
- CIMS.Common.InfoProvider.OnInfo(string.Format("'{0}' 已恢复!如果不需要请及时清除它。", ToString()), 'm');
- return true;
- }
- catch (Exception err) { Common.ExceptionMessenger.OnThrowError("无法从 " + this.ToString() + " 中恢复报表快照!",err); return false; }
- finally { }// designer.Report.EndInit(); }
- }
- public ListViewItem CreateToListViewItem()
- {
- ListViewItem item = new ListViewItem(this.ToString());//快照名
- item.SubItems.Add(ControlsCount.ToString());//控件数目
- item.SubItems.Add(CreatedTime == DateTime.MinValue ? string.Empty : CreatedTime.ToString());//创建日期
- if (IsCreated == false) item.ForeColor = Color.Gray;
- item.Tag = this.ReportSanp;
- item.StateImageIndex = 0;
- return item;
- }
- #endregion
- #region Properties
- /// <summary>
- /// 获取报表快照
- /// </summary>
- public System.IO.MemoryStream ReportSanp { get { return m_reportSanp; } }
- /// <summary>
- /// 获取是否已创建了快照
- /// </summary>
- public new bool IsCreated { get { return m_reportSanp != null; } }
- /// <summary>
- /// 获取或设置快照创建时间
- /// </summary>
- public DateTime CreatedTime
- {
- get { return m_createdTime; }
- set { m_createdTime = value; }
- }
- /// <summary>
- /// 获取或设置快照创建前的控件数目
- /// </summary>
- public int ControlsCount
- {
- get { return m_controlsCount; }
- set { m_controlsCount = value; }
- }
- /// <summary>
- /// 获取或设置快照索引
- /// </summary>
- public int Index
- {
- get { return m_index; }
- set { m_index = value; }
- }
- #endregion
- public bool ClearSanp()
- {
- if (m_reportSanp != null)
- {
- m_reportSanp.Dispose();
- m_reportSanp = null;
- return true;
- }
- return false;
- }
- public void Dispose()
- {
- this.ClearSanp();
- }
- public override string ToString()
- {
- return "快照" + Index.ToString();
- }
- }
绘制边框线:
- protected override void OnCreateGalleryItems()
- {
- base.OnCreateGalleryItems();
- string[] lineStyles = System.Enum.GetNames(typeof(DataDynamics.ActiveReports.BorderLineStyle));
- foreach (string lineStyle in lineStyles)
- {
- DataDynamics.ActiveReports.BorderLineStyle style = (DataDynamics.ActiveReports.BorderLineStyle)System.Enum.Parse(typeof(DataDynamics.ActiveReports.BorderLineStyle), lineStyle);
- GalleryItem gItem = new GalleryItem();
- gItem.Image = CreateLineStyelToImage(style, DEFAULTWIDTH, DEFAULTHEIGHT);
- gItem.HoverImage = CreateLineStyelToImage(style, DEFAULTWIDTH_HOVER, DEFAULTHEIGHT_HOVER);
- gItem.Hint = GetBorderLineStyleStr(style);
- gItem.Tag = style;
- if (style == DataDynamics.ActiveReports.BorderLineStyle.Solid) gItem.Checked = true;
- RibbonGallery.Gallery.Groups[0].Items.Add(gItem);
- }
- }
- private Image CreateLineStyelToImage(DataDynamics.ActiveReports.BorderLineStyle style, Int32 width, Int32 height)
- {
- Bitmap image = new Bitmap(width, height);
- if (style != DataDynamics.ActiveReports.BorderLineStyle.None)
- {
- using (Graphics g = Graphics.FromImage(image))
- {
- Pen pen = this.CreatePen(style);
- using (pen)
- {
- g.DrawLine(pen, 0, image.Height / 2, image.Width, image.Height / 2);
- switch (style)
- {
- case DataDynamics.ActiveReports.BorderLineStyle.Double:
- g.DrawLine(pen, 0, image.Height / 2 + 2, image.Width, image.Height / 2 + 2);
- break;
- case DataDynamics.ActiveReports.BorderLineStyle.ThickDouble:
- g.DrawLine(pen, 0, image.Height / 2 + 4, image.Width, image.Height / 2 + 4);
- break;
- default:
- break;
- }
- }
- }
- }
- return image;
- }
- protected Pen CreatePen(DataDynamics.ActiveReports.BorderLineStyle lineStyle)
- {
- SolidBrush brush = new SolidBrush(this.LineColor);
- Pen pen = new Pen(brush);
- pen.Alignment = System.Drawing.Drawing2D.PenAlignment.Center;
- pen.Width = 1;
- switch (lineStyle)
- {
- case DataDynamics.ActiveReports.BorderLineStyle.Dash:
- pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;
- break;
- case DataDynamics.ActiveReports.BorderLineStyle.DashDot:
- pen.DashStyle = System.Drawing.Drawing2D.DashStyle.DashDot;
- break;
- case DataDynamics.ActiveReports.BorderLineStyle.DashDotDot:
- pen.DashStyle = System.Drawing.Drawing2D.DashStyle.DashDotDot;
- break;
- case DataDynamics.ActiveReports.BorderLineStyle.Dot:
- pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;
- break;
- case DataDynamics.ActiveReports.BorderLineStyle.Double://需要绘制两次
- pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Solid;
- pen.Width = 1;
- break;
- case DataDynamics.ActiveReports.BorderLineStyle.ExtraThickSolid:
- pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Solid;
- pen.Width = 4;
- break;
- case DataDynamics.ActiveReports.BorderLineStyle.ThickDash:
- pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;
- pen.Width = 2;
- break;
- case DataDynamics.ActiveReports.BorderLineStyle.ThickDashDot:
- pen.DashStyle = System.Drawing.Drawing2D.DashStyle.DashDot;
- pen.Width = 2;
- break;
- case DataDynamics.ActiveReports.BorderLineStyle.ThickDashDotDot:
- pen.DashStyle = System.Drawing.Drawing2D.DashStyle.DashDotDot;
- pen.Width = 2;
- break;
- case DataDynamics.ActiveReports.BorderLineStyle.ThickDot:
- pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;
- pen.Width = 2;
- break;
- case DataDynamics.ActiveReports.BorderLineStyle.ThickDouble:
- pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Solid;
- pen.Width = 2;
- break;
- case DataDynamics.ActiveReports.BorderLineStyle.ThickSolid:
- pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Solid;
- pen.Width = 2;
- break;
- default:
- pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Solid;
- break;
- }
- return pen;
- }
- protected string GetBorderLineStyleStr(DataDynamics.ActiveReports.BorderLineStyle lineStyle)
- {
- string result = string.Empty;
- switch (lineStyle)
- {
- case DataDynamics.ActiveReports.BorderLineStyle.Dash:
- result = "虚线";
- break;
- case DataDynamics.ActiveReports.BorderLineStyle.DashDot:
- result = "划线 + 点";
- break;
- case DataDynamics.ActiveReports.BorderLineStyle.DashDotDot:
- result = "划线 + 点 + 点";
- break;
- case DataDynamics.ActiveReports.BorderLineStyle.Dot:
- result = "点";
- break;
- case DataDynamics.ActiveReports.BorderLineStyle.Double:
- result = "双实线";
- break;
- case DataDynamics.ActiveReports.BorderLineStyle.ExtraThickSolid:
- result = "加粗实线";
- break;
- case DataDynamics.ActiveReports.BorderLineStyle.Solid:
- result = "实线";
- break;
- case DataDynamics.ActiveReports.BorderLineStyle.ThickDash:
- result = "粗虚线";
- break;
- case DataDynamics.ActiveReports.BorderLineStyle.ThickDashDot:
- result = "粗的划线 + 点";
- break;
- case DataDynamics.ActiveReports.BorderLineStyle.ThickDashDotDot:
- result = "粗的划线 + 点 + 点";
- break;
- case DataDynamics.ActiveReports.BorderLineStyle.ThickDot:
- result = "粗点";
- break;
- case DataDynamics.ActiveReports.BorderLineStyle.ThickDouble:
- result = "粗的双实线";
- break;
- case DataDynamics.ActiveReports.BorderLineStyle.ThickSolid:
- result = "粗实线";
- break;
- default:
- result= "无边框";
- break;
- }
- return string.Format("{0}({1})", result, lineStyle);
- }
- protected override void OnCreateGalleryItems()
- {
- base.OnCreateGalleryItems();
- //********************************************************自定义颜色
- Color[] colors = CellColors;
- foreach (Color clr in colors)
- {
- CreateColorToImage(0, clr);
- }
- this.RibbonGallery.Gallery.Groups[0].Items[0].Checked = true;
- //********************************************************Web 颜色
- foreach (Color clr in DevExpress.XtraEditors.Popup.ColorListBoxViewInfo.WebColors)
- {
- if (clr == Color.Transparent) continue;
- CreateColorToImage(1, clr);
- }
- //string[] kcs = System.Enum.GetNames(typeof(System.Drawing.KnownColor));
- //foreach (string clrName in kcs)
- //{
- // Color clr = Color.FromName(clrName);
- // CreateColorToImage(1, clr);
- //}
- //********************************************************系统颜色
- foreach (Color clr in DevExpress.XtraEditors.Popup.ColorListBoxViewInfo.SystemColors)
- {
- CreateColorToImage(2, clr);
- }
- }
- private GalleryItem CreateColorToImage(int groupIndex, Color clr)
- { return CreateColorToImage(groupIndex, clr, false); }
- private GalleryItem CreateColorToImage(int groupIndex, Color clr, bool checkedTrue)
- {
- GalleryItem gItem = new GalleryItem();
- gItem.Caption = clr.Name;
- gItem.Tag = clr;
- gItem.Hint = gItem.Caption;
- Bitmap image = new Bitmap(16, 16);
- using (Graphics g = Graphics.FromImage(image))
- {
- SolidBrush brush = new SolidBrush(clr);
- using (brush)
- {
- g.FillRectangle(brush, 0, 0, image.Width, image.Height);
- if (clr == Color.Transparent)
- {
- StringFormat sf = new StringFormat();
- sf.Alignment = StringAlignment.Center;
- sf.LineAlignment = StringAlignment.Center;
- SolidBrush sb = new SolidBrush(Color.Black);
- using (sb)
- {
- g.DrawString("T", this.RibbonGallery.Font, sb, new Rectangle(0, 0, image.Width, image.Height), sf);
- sf.Dispose();
- }
- }
- }
- }
- gItem.Image = image;
- if (checkedTrue) gItem.Checked = true;
- RibbonGallery.Gallery.Groups[groupIndex].Items.Add(gItem);
- return gItem;
- }
相关设置捷径:
相关代码:
基类:
- public abstract class PageGalleryDropDownBase : GalleryDropDown
- {
- private ReportDesignerRibbonForm owner = null;
- private BarButtonItem parentItem = null;
- protected DataDynamics.ActiveReports.PageSettings m_pageSettings=null;
- GalleryItemGroup group = new GalleryItemGroup();
- protected abstract PageGalleryItem[] Items { get; }
- protected virtual int RowCount { get { return group.Items.Count; } }
- /// <summary>
- /// 如果定义为-1,则为项目数目不确定
- /// </summary>
- protected abstract int CreateItemsCount { get; }
- public enum CommandsCategory
- {
- /// <summary>
- /// 空命令
- /// </summary>
- None = 0,
- /// <summary>
- /// 页边距设置
- /// </summary>
- PageMargins,
- /// <summary>
- /// 纸张方向设置
- /// </summary>
- PageOrientation,
- /// <summary>
- /// 纸张大小设置
- /// </summary>
- PaperSize,
- /// <summary>
- /// 打印纸张来源设置
- /// </summary>
- PaperSources,
- /// <summary>
- /// 逐份打印设置
- /// </summary>
- PrintCollate,
- /// <summary>
- /// 双面打印设置
- /// </summary>
- PrintDuplex,
- /// <summary>
- /// 设置打印机
- /// </summary>
- Printer,
- }
- protected Image GetImageFromResource(string resourceName) { return Utils.GetImage(resourceName); }
- protected PageGalleryDropDownBase(ReportDesignerRibbonForm owner, BarButtonItem parentItem)
- {
- this.owner = owner;
- this.m_pageSettings = owner.Report.PageSettings;
- this.parentItem = parentItem;
- this.parentItem.DropDownControl = this;
- if (this.parentItem.ButtonStyle != BarButtonStyle.DropDown) this.parentItem.ButtonStyle = BarButtonStyle.DropDown;
- this.Ribbon = owner.Ribbon;
- this.OnInitGallery();
- }
- protected virtual void OnInitGallery()
- {
- Gallery.Appearance.ItemCaption.TextOptions.HAlignment = HorzAlignment.Near;
- Gallery.Appearance.ItemCaption.Options.UseTextOptions = true;
- Gallery.Appearance.ItemDescription.TextOptions.HAlignment = HorzAlignment.Near;
- Gallery.Appearance.ItemDescription.Options.UseTextOptions = true;
- Gallery.ColumnCount = 1;
- Gallery.ShowGroupCaption = false;
- Gallery.ShowItemText = true;
- Gallery.DrawImageBackground = false;
- Gallery.Groups.Add(group);
- GalleryItemClick += new GalleryItemClickEventHandler(OnGalleryItemClick);
- }
- /// <summary>
- /// 更新列表项目(如:当设计单位更改后...)
- /// </summary>
- public virtual void Update() { createdFlag = false; m_pageSettings = this.Designer.Report.PageSettings; }
- /// <summary>
- /// 更新父按钮的工具提示
- /// </summary>
- public virtual void UpdateParentItemHint() { }
- private bool createdFlag = false;
- protected virtual bool CanBeforePopupClear { get { return true; } }
- protected override void OnBeforePopup(CancelEventArgs e)
- {
- base.OnBeforePopup(e);
- BeginUpdate();
- if (createdFlag == false || CanBeforePopupClear) group.Items.Clear();
- bool checkedFlag = false;
- foreach (PageGalleryItem item in Items)
- {
- item.Checked = false;
- if (createdFlag == false || CanBeforePopupClear) group.Items.Add(item);
- bool flag = IsItemChecked(item);
- if (checkedFlag == false) item.Checked = flag;
- if (flag == true) checkedFlag = true;
- }
- Gallery.RowCount = RowCount;
- EndUpdate();
- createdFlag = true;
- }
- #region Properties
- public DataDynamics.ActiveReports.Design.Designer Designer { get { return Owner.Designer; } }
- public ReportDesignerRibbonForm Owner { get { return owner; } }
- public BarButtonItem ParentItem { get { return parentItem; } }
- /// <summary>
- /// 获取已勾选的项
- /// </summary>
- public PageGalleryItem GetCheckedItem
- {
- get
- {
- foreach (GalleryItemGroup group in this.Gallery.Groups)
- {
- foreach (PageGalleryItem gItem in group.Items)
- {
- if (gItem.Checked) return gItem;
- }
- }
- return null;
- }
- }
- /// <summary>
- /// 获取打印机页面设置
- /// </summary>
- public DataDynamics.ActiveReports.PageSettings PageSettings { get { return m_pageSettings; } }
- protected virtual bool IsItemChecked(PageGalleryItem item)
- {
- return false;
- }
- /// <summary>
- /// 获取是否为公制单位(cm)
- /// </summary>
- public bool IsMetric
- {
- get { return this.Owner.Designer.DesignUnits == DataDynamics.ActiveReports.Design.MeasurementUnits.Metric; }
- }
- #endregion
- protected override void Dispose(bool disposing)
- {
- try
- {
- if (disposing)
- {
- GalleryItemClick -= new GalleryItemClickEventHandler(OnGalleryItemClick);
- }
- }
- finally
- {
- base.Dispose(disposing);
- }
- }
- void OnGalleryItemClick(object sender, GalleryItemClickEventArgs e)
- {
- if (e.Item.Checked) return;
- PageGalleryItem commandItem = e.Item as PageGalleryItem;
- OnGalleryItemClick(commandItem);
- }
- protected virtual void OnGalleryItemClick(PageGalleryItem commandItem)
- {
- this.Owner.DesignChanged = true;
- }
- }
- public abstract class PageGalleryDropDown : PageGalleryDropDownBase
- {
- protected PageGalleryItem[] items = null;
- private CommandsCategory command = CommandsCategory.None;
- protected object[] args = null;
- protected PageGalleryDropDown(ReportDesignerRibbonForm owner,BarButtonItem parentItem, CommandsCategory command)
- : base(owner,parentItem)
- {
- this.command = command;
- }
- protected PageGalleryDropDown(ReportDesignerRibbonForm owner, BarButtonItem parentItem, CommandsCategory command, object[] args)
- : base(owner,parentItem)
- {
- this.command = command;
- this.args = args;
- }
- public override void Update()
- {
- base.Update();
- items = null;
- args = null;
- }
- protected override PageGalleryItem[] Items
- {
- get
- {//如果ItemsCount==-1,则需要重写
- if (items == null) CreateItems();
- return items;
- }
- }
- /// <summary>
- /// 获取所属的命令集
- /// </summary>
- protected CommandsCategory Command { get { return command; } }
- protected virtual object[] Args {
- get { return args; }
- set { args = value; }
- }
- protected virtual void CreateItems() {
- items = new PageGalleryItem[this.CreateItemsCount];
- for (int i = 0; i < this.CreateItemsCount; i++)
- items[i] = CreateGalleryItem(args[i]);//args为子命令枚举成员
- }
- protected System.Drawing.Printing.PrinterSettings CreatePrinterSettings()
- {
- System.Drawing.Printing.PrinterSettings ps = new PrinterSettings();
- ps.PrinterName = this.Designer.Report.Document != null ? this.Designer.Report.Document.Printer.PrinterName : ps.DefaultPageSettings.PrinterSettings.PrinterName;
- return ps;
- }
- /// <summary>
- /// 创建页面设置相关的下拉项目
- /// </summary>
- /// <param name="arg">子命令枚举成员</param>
- /// <returns></returns>
- protected virtual PageGalleryItem CreateGalleryItem(object arg) { return null; }
- }
- public class PrinterGalleryDropDow : PageGalleryDropDown
- {
- public event EventHandler PrinterChanged = null;
- public PrinterGalleryDropDow(ReportDesignerRibbonForm owner, BarButtonItem item)
- : base(owner, item, CommandsCategory.Printer)
- {
- Gallery.ImageSize = new Size(48, 48);
- }
- static string GetPrinterDescription(string printerName)
- {
- return IsNetPrinter(printerName) ? "网络打印机" : "本地打印机";
- }
- static bool IsNetPrinter(string printerName)
- {
- return printerName.IndexOf(@"/") > -1;
- }
- const int MaxPrinterGalleryRowCount = 7;
- protected override int CreateItemsCount { get { return -1; } }
- protected override bool CanBeforePopupClear { get { return false; } }
- public string GetDefaultPrinter
- {
- get
- {
- string defaultPrinter = string.Empty;
- if (this.Designer.Report.Document != null)
- defaultPrinter = this.Designer.Report.Document.Printer.PrinterName;
- else
- {
- PrinterSettings ps = new PrinterSettings();
- defaultPrinter = ps.DefaultPageSettings.PrinterSettings.PrinterName;
- }
- return defaultPrinter;
- }
- }
- public override void Update()
- {
- base.Update();
- this.CreateItems();
- this.SetPrinter(GetDefaultPrinter);
- }
- protected override void CreateItems()
- {
- List<PageGalleryItem> itemsAll = new List<PageGalleryItem>();
- Image imageLocal = global::CIMS.Report.Designer.ReportDesignerResources.LocalPrinter;
- Image imageNet = global::CIMS.Report.Designer.ReportDesignerResources.NetPrinter;
- string defaultPrinter = GetDefaultPrinter;
- foreach (string printerName in System.Drawing.Printing.PrinterSettings.InstalledPrinters)
- {
- PageGalleryItem item = new PageGalleryItem(IsNetPrinter(printerName) ? imageNet : imageLocal,"打印到 "+ printerName, GetPrinterDescription(printerName), printerName);
- if (printerName == defaultPrinter) item.Checked = true;
- itemsAll.Add(item);
- }
- items = new PageGalleryItem[itemsAll.Count];
- itemsAll.CopyTo(items, 0);
- }
- public override void UpdateParentItemHint()
- {
- this.UpdateParentItemHint(this.GetDefaultPrinter);
- }
- public void UpdateParentItemHint(string printerName)
- {
- string title = string.Empty;
- foreach (PageGalleryItem item in Items)
- {
- if (IsItemChecked(item))
- {
- title = item.Caption;
- break;
- }
- }
- this.ParentItem.Hint = title + "/n" + GetPrinterDescription(printerName);
- }
- protected override int RowCount { get { return Math.Min(MaxPrinterGalleryRowCount, base.RowCount); } }
- protected override bool IsItemChecked(PageGalleryItem item)
- {
- if (this.Designer.Report.Document == null)
- {
- //默认
- return false;
- }
- string printerName = item.CommandParameter.ToString();
- return Designer.Report.Document.Printer.PrinterName == item.CommandParameter.ToString();
- //return PageSettings.PaperName == paperSize.PaperName || (PageSettings.PaperWidth == paperSize.Width/100 && PageSettings.PaperHeight == paperSize.Height/100);
- }
- protected override void OnGalleryItemClick(PageGalleryItem commandItem)
- {
- base.OnGalleryItemClick(commandItem);
- if (this.Designer.Report.Document == null)
- {
- System.Windows.Forms.MessageBox.Show("当前报表设计还没有创建Document对象!", "设置打印机", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Warning);
- return;
- }
- string printerName = commandItem.CommandParameter.ToString();
- this.SetPrinter(printerName);
- }
- protected void SetPrinter(string printerName)
- {
- if (Designer.Report.Document.Printer.PrinterName == printerName) return;
- this.Designer.Report.Document.Printer.PrinterName = printerName;
- this.UpdateParentItemHint(printerName);
- if (PrinterChanged != null) PrinterChanged(this, EventArgs.Empty);
- }
完.