Esempio n. 1
0
        /// <summary>
        /// 显示打印预览窗体
        /// </summary>
        /// <param name="component">可以是GridContronl或者TreeList或者其他</param>
        /// <param name="headerTitle">标题</param>
        /// <param name="landscape">true表示横向,false表示纵向</param>
        /// <param name="headerFont">标题字体</param>
        public static void ShowPreview(IPrintable component, string headerTitle, bool landscape, Font headerFont)
        {
            PrintingSystem ps = new DevExpress.XtraPrinting.PrintingSystem();

            DevExpress.XtraPrinting.PrintableComponentLink link = new DevExpress.XtraPrinting.PrintableComponentLink(ps);
            ps.Links.Add(link);
            link.Component = component;            //这里可以是可打印的部件

            PageHeaderFooter phf = link.PageHeaderFooter as PageHeaderFooter;

            phf.Header.Content.AddRange(new string[] { "", headerTitle, "" });
            phf.Header.Font          = headerFont;
            phf.Header.LineAlignment = BrickAlignment.Center;
            phf.Footer.Content.AddRange(new string[] { DateTime.Now.ToString("yyyy-MM-dd"), "", "[Page # of Pages #]" });
            phf.Footer.LineAlignment = BrickAlignment.Center;
            link.Landscape           = landscape;
            link.CreateDocument();             //建立文档


            //ps.PreviewFormEx.Menu.MenuItems[0].MenuItems.RemoveAt(6) ;
            //ps.PreviewFormEx.Menu.MenuItems[0].MenuItems.RemoveAt(5);
            //ps.PreviewFormEx.Menu.MenuItems[0].MenuItems.RemoveAt(4);
            //ps.PreviewFormEx.PrintPreviewBar.Buttons.RemoveAt(4);
            //ps.PreviewFormEx.PrintPreviewBar.Buttons.RemoveAt(23);
            //ps.PreviewFormEx.PrintPreviewBar.Buttons.RemoveAt(23);lgm


            ps.PreviewFormEx.Text = headerTitle;

            ps.PreviewFormEx.Show();            //进行预览
        }
Esempio n. 2
0
        /// <summary>
        /// 打印操作
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void simpleButton1_Click_1(object sender, EventArgs e)
        {
            try
            {
                //this.layoutControl1.ShowPrintPreview();
                //this.layoutControl1.Print();
                //layoutControl1.ExportToXls("C:\\1.xls");
                //声明PrintingSystem
                PrintingSystem ps = new DevExpress.XtraPrinting.PrintingSystem();
                DevExpress.XtraPrinting.PrintableComponentLink link = null;
                link = new DevExpress.XtraPrinting.PrintableComponentLink(ps);
                ps.Links.Add(link);
                link.Component = layoutControl1; //将layoutcontrol控件和打印组件连接
                link.CreateDocument();           //建立文档
                ps.PageSettings.PaperKind = PaperKind.A4;

                //设置表格边距
                ps.PageSettings.TopMargin    = 2;
                ps.PageSettings.BottomMargin = 2;
                ps.PageSettings.LeftMargin   = 2;
                ps.PageSettings.RightMargin  = 2;
                //ps.PrintDlg();//调打印设置窗体
                //ps.PreviewFormEx.Show();//预览窗体
                ps.Print();
            }
            catch (Exception ex)
            {
                DrectSoft.Common.Ctrs.DLG.MyMessageBox.Show(1, ex);
            }
        }
Esempio n. 3
0
        public static void ExportXls(IPrintable Printer, string printCaption, Control.ControlCollection Controls)
        {
            if (Printer == null)
            {
                return;
            }
            OnBestFitColumns(Controls);
            PrintCaption = printCaption;
            DevExpress.XtraPrinting.PrintingSystem         ps   = new DevExpress.XtraPrinting.PrintingSystem();
            DevExpress.XtraPrinting.PrintableComponentLink link = new DevExpress.XtraPrinting.PrintableComponentLink(ps);
            link.Component = Printer;
            link.CreateReportHeaderArea += new DevExpress.XtraPrinting.CreateAreaEventHandler(printableComponentLink_CreateReportHeaderArea);

            link.PaperKind = System.Drawing.Printing.PaperKind.A4;

            link.Margins.Bottom = link.Margins.Left = link.Margins.Right = link.Margins.Top = 50;

            link.CreateDocument();
            string         fileName = string.Empty;
            SaveFileDialog save     = new SaveFileDialog();

            save.Filter = "Exel 2013 (*.xls)|*.xls";
            if (save.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                fileName = save.FileName;
            }

            if (string.IsNullOrEmpty(fileName))
            {
                return;
            }
            link.ExportToXls(fileName);
        }
Esempio n. 4
0
        /// <summary>
        /// 打印GridControl
        /// </summary>
        /// <param name="control">需要被打印的GridControl</param>
        public static void PrintGridControl(GridControl control)
        {
            DevExpress.XtraPrintingLinks.CompositeLink compositeLink = new DevExpress.XtraPrintingLinks.CompositeLink();
            DevExpress.XtraPrinting.PrintingSystem     ps            = new DevExpress.XtraPrinting.PrintingSystem();

            compositeLink.PrintingSystem = ps;
            compositeLink.Landscape      = true;
            compositeLink.PaperKind      = System.Drawing.Printing.PaperKind.A4;

            DevExpress.XtraPrinting.PrintableComponentLink link = new DevExpress.XtraPrinting.PrintableComponentLink(ps);
            ps.PageSettings.Landscape = true;


            //   PageHeaderFooter phf = compositeLink.PageHeaderFooter as PageHeaderFooter;

            //设置页眉
            //phf.Header.Content.Clear();
            //phf.Header.Content.AddRange(new string[] { "", _PrintHeader, "" });
            //phf.Header.Font = new System.Drawing.Font("宋体", 14, System.Drawing.FontStyle.Bold);
            //phf.Header.LineAlignment = BrickAlignment.Center;

            //设置页脚
            //phf.Footer.Content.Clear();
            //phf.Footer.Content.AddRange(new string[] { "", "", "1" });
            //phf.Footer.Font = new System.Drawing.Font("宋体", 9, System.Drawing.FontStyle.Regular);
            //phf.Footer.LineAlignment = BrickAlignment.Center;


            link.Component = control;

            compositeLink.Links.Add(link);

            link.CreateDocument();   //建立文档
            ps.PreviewFormEx.Show(); //进行预览
        }
        private void btnPrint_Click(object sender, EventArgs e)
        {
            DevExpress.XtraPrinting.PrintingSystem         ps  = new DevExpress.XtraPrinting.PrintingSystem();
            DevExpress.XtraPrinting.PrintableComponentLink pcl = new DevExpress.XtraPrinting.PrintableComponentLink(ps);

            pcl.CreateReportHeaderArea += this.pcl_CreateReportHeaderArea;
            pcl.Component = gridIssues;
            pcl.Landscape = true;
            pcl.CreateDocument();
            ps.PreviewFormEx.ShowDialog();
        }
        private void btnPrint_Click(object sender, EventArgs e)
        {
            DevExpress.XtraPrinting.PrintingSystem ps = new DevExpress.XtraPrinting.PrintingSystem();
            DevExpress.XtraPrinting.PrintableComponentLink pcl = new DevExpress.XtraPrinting.PrintableComponentLink(ps);

            pcl.CreateReportHeaderArea += this.pcl_CreateReportHeaderArea;

            pcl.Component = gridControl1;
            pcl.Landscape = true;

            pcl.CreateDocument();
            ps.PreviewFormEx.ShowDialog();
        }
Esempio n. 7
0
 protected virtual object CreateLink(DevExpress.XtraPrinting.IPrintable printable)
 {
     if (_PrintParam != null)
     {
         _PrintableLink.PrintingSystem.PageSettings.Landscape = _PrintParam.Landscape;
     }
     if (_PrintableLink == null)
     {
         return(null);
     }
     _PrintableLink.Component = printable;
     _PrintableLink.CreateDocument();
     return(_PrintableLink);
 }
Esempio n. 8
0
        public static void PreviewReport(IPrintable Printer, string printCaption, Control.ControlCollection Controls)
        {
            if (Printer == null)
            {
                return;
            }
            OnBestFitColumns(Controls);
            PrintCaption = printCaption;
            DevExpress.XtraPrinting.PrintingSystem         ps   = new DevExpress.XtraPrinting.PrintingSystem();
            DevExpress.XtraPrinting.PrintableComponentLink link = new DevExpress.XtraPrinting.PrintableComponentLink(ps);
            link.Component = Printer;
            link.PaperKind = System.Drawing.Printing.PaperKind.A4;
            link.CreateReportHeaderArea += new DevExpress.XtraPrinting.CreateAreaEventHandler(printableComponentLink_CreateReportHeaderArea);
            link.CreateReportFooterArea += new CreateAreaEventHandler(printableComponentLink_CreateReportFooterArea);



            link.Margins.Bottom = link.Margins.Left = link.Margins.Right = link.Margins.Top = 50;

            link.CreateDocument();
            link.ShowPreview();
        }
Esempio n. 9
0
        private void btnPrint_Click(object sender, System.EventArgs e)
        {
            PageHeaderFooter ph = printableComponentLink1.PageHeaderFooter as PageHeaderFooter;

            ph.Header.Content.Clear();
            ph.Header.Content.AddRange(new string[] { "All Income Report for Date " + strDate, "", "" });
            printableComponentLink1.CreateDocument(printingSystem1);
            printingSystem1.PreviewFormEx.AutoScale = true;
            printingSystem1.PreviewFormEx.ForeColor = System.Drawing.Color.Black;
            printingSystem1.PreviewFormEx.Owner     = this;
            printingSystem1.PreviewFormEx.PrintingSystem.Print();
//
//			printableComponentLink1.CreateDocument();
//			printableComponentLink1.PrintingSystem.PreviewForm.AutoScale = true;
//			printableComponentLink1.PrintingSystem.Print();

//			Cursor currentCursor = Cursor.Current;
//			Cursor.Current = Cursors.WaitCursor;
//
//			BrickGraphics gr = printingSystem1.Graph;
//			SendKeys.SendWait("^{PRTSC}");
//			Image img = ClipboardImage;
//			printingSystem1.Begin();
//			gr.Modifier = BrickModifier.Detail;
//			RectangleF r = new RectangleF(new PointF(0, 0), gr.ClientPageSize);
//			gr.DrawEmptyBrick(new RectangleF(0, 0, 100, 100));
//
//			if(img != null)
//			{
////				if(!autoWidth)
//				r = new RectangleF(0, 0, 870, 610);
//				CustomBrick brick = gr.DrawImage(img, r, BorderSide.None, Color.Transparent);
//				brick.Separable = true;
//			}
//			else
//				MessageBox.Show("Image is null...");
//
//			gr.Font = new Font("Arial", 8, FontStyle.Underline);
//			gr.Modifier = BrickModifier.MarginalFooter;
//
//			gr.BackColor = Color.Transparent;
//			r = new RectangleF(0, 0, 0, gr.Font.Height);
//
//			PageInfoBrick pibrick = gr.DrawPageInfo(PageInfo.Number, "XtraPrintingSystem by Developer Express inc.", Color.Blue, r, BorderSide.None);
//			pibrick.Url = "www.devexpress.com";
//			pibrick.Hint = pibrick.Url;
//			pibrick.Alignment = BrickAlignment.Far;
//			pibrick.AutoWidth = true;
//
//			printingSystem1.End();
////			if(closeCount == 0)
////			{
////				printSystem1.PreviewForm.Closed += new EventHandler(ClosePreview);
////				closeCount++;
////			}
//			//printingSystem1.PreviewForm.Show();
//
//			printingSystem1.PreviewForm.Activate();
//			printingSystem1.PreviewForm.PrintingSystem.PageSettings.Landscape = true;
//			printingSystem1.PreviewForm.PrintingSystem.Print();
//
//			Cursor.Current = currentCursor;
        }
Esempio n. 10
0
        /*
        * "[Page #]" (represented via the PreviewStringId.PageInfo_PageNumber property)
        * "[Page # of Pages #]" (represented via the PreviewStringId.PageInfo_PageNumberOfTotal property)
        * "[Date Printed]" (represented via the PreviewStringId.PageInfo_PageDate property)
        * "[Time Printed]" (represented via the PreviewStringId.PageInfo_PageTime property)
        * "[User Name]" (represented via the PreviewStringId.PageInfo_PageUserName property)
        */
        public static PrintableComponentLink GetPrintableComponentLink(
            IPrintable gridControl,
            String reportHeader,
            Image ReportHeaderImage,
            String rtfGridHeader,
            float rtfGridHeaderHeight,
            String mainTitle,
            String subTitle,
            String reportFooter,
            String rtfGridFooter)
        {
            float height = 0;

            DevExpress.XtraPrinting.PrintingSystem printingSystem1;
            printingSystem1 = new DevExpress.XtraPrinting.PrintingSystem();
            ((System.ComponentModel.ISupportInitialize)(printingSystem1)).BeginInit();
            DevExpress.XtraPrinting.PrintableComponentLink printableComponentLink1;
            printableComponentLink1 = new DevExpress.XtraPrinting.PrintableComponentLink();
            printableComponentLink1.PaperKind = System.Drawing.Printing.PaperKind.A4;
            printableComponentLink1.Margins.Left = 50;
            printableComponentLink1.Margins.Right = 50;
            printableComponentLink1.Margins.Top = 50;
            printableComponentLink1.Margins.Bottom = 50;
            printingSystem1.Links.AddRange(new object[] { printableComponentLink1 });
            printableComponentLink1.Component = gridControl;
            printableComponentLink1.PrintingSystem = printingSystem1;

            DevExpress.XtraPrinting.PageHeaderArea headerArea;
            headerArea = new DevExpress.XtraPrinting.PageHeaderArea();
            headerArea.Content.Add(reportHeader);
            headerArea.LineAlignment = DevExpress.XtraPrinting.BrickAlignment.Near;

            #region Đầu trang
            if (rtfGridHeader != null)
            {
                printableComponentLink1.RtfReportHeader = rtfGridHeader;
                height = rtfGridHeaderHeight;
            }
            printableComponentLink1.CreateReportHeaderArea += delegate(object sender, DevExpress.XtraPrinting.CreateAreaEventArgs e)
            {
                float currentHeight = height;

                #region Giải pháp 1
                Image headerImage = (ReportHeaderImage == null ?
                    FWImageDic.LOGO_IMAGE48 : ReportHeaderImage);

                DevExpress.XtraPrinting.ImageBrick logo;
                logo = e.Graph.DrawImage(headerImage,
                    new RectangleF(10, 5, headerImage.Width, headerImage.Height),
                    DevExpress.XtraPrinting.BorderSide.None, Color.Transparent);
                //currentHeight += headerImage.Height;
                #endregion

                if (mainTitle != null)
                {
                    DevExpress.XtraPrinting.TextBrick brick;
                    brick = e.Graph.DrawString(mainTitle, Color.Navy, new RectangleF(0, currentHeight, 620, 40), DevExpress.XtraPrinting.BorderSide.None);
                    currentHeight += 40;
                    brick.Font = new Font("Tahoma", 20);
                    brick.StringFormat = new DevExpress.XtraPrinting.BrickStringFormat(StringAlignment.Center);
                    brick.BackColor = Color.White;
                    brick.ForeColor = Color.Black;

                }

                if (subTitle != null)
                {
                    DevExpress.XtraPrinting.TextBrick brickDate;
                    brickDate = e.Graph.DrawString(subTitle, Color.Navy, new RectangleF(0, currentHeight, 620, 40), DevExpress.XtraPrinting.BorderSide.None);
                    currentHeight += 40;
                    brickDate.Font = new Font("Tahoma", 10);
                    brickDate.StringFormat = new DevExpress.XtraPrinting.BrickStringFormat(StringAlignment.Center);
                    brickDate.BackColor = Color.White;
                    brickDate.ForeColor = Color.Black;
                }
            };
            #endregion

            if(rtfGridFooter!= null)
                printableComponentLink1.RtfReportFooter = rtfGridFooter;

            #region Header Footer
            DevExpress.XtraPrinting.PageFooterArea footerArea;
            footerArea = new DevExpress.XtraPrinting.PageFooterArea();
            footerArea.Content.Add(reportFooter);
            footerArea.LineAlignment = DevExpress.XtraPrinting.BrickAlignment.Near;

            DevExpress.XtraPrinting.PageHeaderFooter pageHeaderFooter;
            pageHeaderFooter = new DevExpress.XtraPrinting.PageHeaderFooter(headerArea, footerArea);
            printableComponentLink1.PageHeaderFooter = pageHeaderFooter;
            #endregion

            ((System.ComponentModel.ISupportInitialize)(printingSystem1)).EndInit();

            printableComponentLink1.CreateDocument();

            return printableComponentLink1;
        }
Esempio n. 11
-1
        /// <summary>
        /// ��ʾ��ӡԤ������
        /// </summary>
        /// <param name="component">������GridContronl����TreeList��������</param>
        /// <param name="headerTitle">����</param>
        /// <param name="landscape">true��ʾ����false��ʾ����</param>
        /// <param name="headerFont">��������</param>
        public static void ShowPreview(IPrintable component, string headerTitle, bool landscape, Font headerFont)
        {
            PrintingSystem ps = new DevExpress.XtraPrinting.PrintingSystem();
            DevExpress.XtraPrinting.PrintableComponentLink link = new DevExpress.XtraPrinting.PrintableComponentLink(ps);
            ps.Links.Add(link);
            link.Component = component;//��������ǿɴ�ӡ�IJ���

            PageHeaderFooter phf = link.PageHeaderFooter as PageHeaderFooter;
            phf.Header.Content.AddRange(new string[]{"", headerTitle, ""});
            phf.Header.Font = headerFont;
            phf.Header.LineAlignment = BrickAlignment.Center;
            phf.Footer.Content.AddRange(new string[] { DateTime.Now.ToString("yyyy-MM-dd"), "", "[Page # of Pages #]" });
            phf.Footer.LineAlignment = BrickAlignment.Center;
            link.Landscape = landscape;
            link.CreateDocument(); //�����ĵ�

            //ps.PreviewFormEx.Menu.MenuItems[0].MenuItems.RemoveAt(6) ;
            //ps.PreviewFormEx.Menu.MenuItems[0].MenuItems.RemoveAt(5);
            //ps.PreviewFormEx.Menu.MenuItems[0].MenuItems.RemoveAt(4);
            //ps.PreviewFormEx.PrintPreviewBar.Buttons.RemoveAt(4);
            //ps.PreviewFormEx.PrintPreviewBar.Buttons.RemoveAt(23);
            //ps.PreviewFormEx.PrintPreviewBar.Buttons.RemoveAt(23);lgm

            ps.PreviewFormEx.Text=headerTitle;

            ps.PreviewFormEx.Show();//����Ԥ��
        }