///// <summary> ///// 打印指定页 ///// </summary> //private int intSpecialPageIndex = - 1; /// <summary> /// 打印指定页 /// </summary> /// <param name="vPageIndex">指定页号</param> public void PrintSpecialPage(int vPageIndex) { this.PrinterSettings.PrintRange = PrintRange.CurrentPage; this.myCurrentDocumentPage = myPages[vPageIndex]; this.Print(); }
/// <summary> /// 更新当前页面对象 /// </summary> /// <returns>操作是否改变了当前页面对象</returns> protected bool UpdateCurrentPage() { if (_Pages != null) { MultiPageTransform trans = ( MultiPageTransform )this.myTransform; PrintPage cpage = null; System.Drawing.Rectangle rect = new System.Drawing.Rectangle( -this.AutoScrollPosition.X, -this.AutoScrollPosition.Y, this.ClientSize.Width, this.ClientSize.Height); int MaxHeight = 0; foreach (PrintPage page in _Pages) { System.Drawing.Rectangle rect2 = System.Drawing.Rectangle.Intersect( page.ClientBounds, rect); if (!rect2.IsEmpty) { if (MaxHeight < rect2.Height) { cpage = page; MaxHeight = rect2.Height; } } } if (cpage != myCurrentPage) { myCurrentPage = cpage; return(true); } } return(false); }
/// <summary> /// 跳到指定页,页号从0开始计算。 /// </summary> /// <param name="PageIndex">从0开始的页号</param> /// <returns>操作是否成功</returns> public bool MoveToPage(int PageIndex) { if (_Pages != null && PageIndex >= 0 && PageIndex < _Pages.Count) { PrintPage page = _Pages[PageIndex]; this.SetAutoScrollPosition(new System.Drawing.Point(0, page.ClientBounds.Top)); myCurrentPage = page; this.Invalidate(); return(true); } return(false); }
/// <summary> /// 创建指定页的图元数据 /// </summary> /// <param name="page">页面对象</param> /// <param name="DrawMargin">是否绘制边距线</param> /// <returns>包含图元数据的字节数组</returns> public byte[] GetMetafile(PrintPage page, bool DrawMargin) { XPageSettings pageSettings = page.PageSettings; System.Drawing.Imaging.Metafile meta = null; using (DeviceContexts dc = DeviceContexts.CreateCompatibleDC(IntPtr.Zero)) { System.IO.MemoryStream stream = new System.IO.MemoryStream(); meta = new System.Drawing.Imaging.Metafile( stream, dc.HDC, new System.Drawing.Rectangle( 0, 0, (int)page.PageSettings.ViewPaperWidth, (int)page.PageSettings.ViewPaperHeight), //System.Drawing.Imaging.MetafileFrameUnit.Document ); PrintUtil.ConvertUnit(myDocument.DocumentGraphicsUnit)); using (System.Drawing.Graphics g2 = System.Drawing.Graphics.FromImage(meta)) { if (intBackColor.A != 0) { g2.Clear(this.intBackColor); } g2.PageUnit = myDocument.DocumentGraphicsUnit; PageFrameDrawer drawer = new PageFrameDrawer(); drawer.DrawMargin = DrawMargin; drawer.BackColor = System.Drawing.Color.Transparent; drawer.BorderColor = this.intBorderColor; drawer.BorderWidth = 1; drawer.LeftMargin = (int)page.ViewLeftMargin; drawer.TopMargin = (int)page.ViewTopMargin; drawer.RightMargin = (int)page.ViewRightMargin; drawer.BottomMargin = (int)page.ViewBottomMargin; drawer.Bounds = new System.Drawing.Rectangle( 0, 0, (int)pageSettings.ViewPaperWidth, (int)pageSettings.ViewPaperHeight); drawer.BackgroundImage = this.PageBackgroundImage; g2.ScaleTransform(this.XZoomRate, this.YZoomRate); drawer.DrawPageFrame(g2, System.Drawing.Rectangle.Empty); DrawPage(page, g2, page.Bounds, true); } meta.Dispose(); dc.Dispose(); return(stream.ToArray()); } }
public PageDocumentPaintEventArgs( Graphics graphics, Rectangle clipRectangle, IPageDocument document, PrintPage page, PageContentPartyStyle contentStyle) { _Graphics = graphics; _ClipRectangle = clipRectangle; _Document = document; _Page = page; _ContentStyle = contentStyle; if (page != null) { _PageIndex = page.GlobalIndex + 1; } }
/// <summary> /// 已重载:打印一页内容 /// </summary> /// <param name="e">事件参数</param> protected override void OnPrintPage(System.Drawing.Printing.PrintPageEventArgs e) { base.OnPrintPage(e); if (e.Cancel) { return; } if (myPageEnumerator != null) { PrintPage myPage = (PrintPage)myPageEnumerator.Current; //myPage.Document.PageIndex = myPage.GlobalIndex; //myDocument.PageIndex = intCurrentPageIndex ; System.Drawing.Rectangle ClipRect = new System.Drawing.Rectangle( myPage.Left, myPage.Top, myPage.Width, myPage.Height); bool bolJumpPrint = false; if (this.JumpPrint.Enabled && this.JumpPrint.Page == myPage) { //if( this.JumpPrint.Position > myPage.Top && this.JumpPrint.Position < myPage.Bottom ) { int dy = this.JumpPrint.Position;// -myPage.Top; ClipRect.Offset(0, dy); ClipRect.Height = ClipRect.Height - dy; bolJumpPrint = true; } } if (bolJumpPrint) { OnPaintPage(myPage, e.Graphics, ClipRect, false, false, e); } else { OnPaintPage(myPage, e.Graphics, ClipRect, true, true, e); } e.HasMorePages = myPageEnumerator.MoveNext(); intPrintedPageCount++; } }
/// <summary> /// 创建指定页的BMP图片对象 /// </summary> /// <param name="page">页面对象</param> /// <param name="DrawMargin">是否绘制页边距线</param> /// <returns>创建的BMP图片对象</returns> public System.Drawing.Bitmap GetPageBmp(PrintPage page, bool DrawMargin) { XPageSettings pageSettings = page.PageSettings; double rate = GraphicsUnitConvert.GetRate( myDocument.DocumentGraphicsUnit, System.Drawing.GraphicsUnit.Pixel); int width = (int)Math.Ceiling(pageSettings.ViewPaperWidth / rate); int height = (int)Math.Ceiling(pageSettings.ViewPaperHeight / rate); System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(width, height); using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bmp)) { if (intBackColor.A != 0) { g.Clear(this.intBackColor); } g.PageUnit = myDocument.DocumentGraphicsUnit; PageFrameDrawer drawer = new PageFrameDrawer(); drawer.DrawMargin = DrawMargin; drawer.BackColor = System.Drawing.Color.Transparent; drawer.BorderColor = this.intBorderColor; drawer.BorderWidth = 1; drawer.LeftMargin = (int)page.ViewLeftMargin; drawer.TopMargin = (int)page.ViewTopMargin; drawer.RightMargin = (int)page.ViewRightMargin; drawer.BottomMargin = (int)page.ViewBottomMargin; drawer.Bounds = new System.Drawing.Rectangle( 0, 0, (int)page.ViewPaperWidth, (int)page.ViewPaperHeight); drawer.BackgroundImage = this.PageBackgroundImage; drawer.DrawPageFrame(g, System.Drawing.Rectangle.Empty); DrawPage(page, g, page.Bounds, true); } return(bmp); }
/// <summary> /// 页面滚动事件处理 /// </summary> protected override void OnXScroll() { if (this.Pages != null && this.ViewMode == PageViewMode.Page) { PrintPage page = this.myCurrentPage; if (this.UpdateCurrentPage()) { using (System.Drawing.Graphics g = this.CreateGraphics()) { DrawPageFrame(page, g, System.Drawing.Rectangle.Empty, false); DrawPageFrame(this.CurrentPage, g, System.Drawing.Rectangle.Empty, false); } // if( page == null) // rect = cpage.ClientBounds ; // else // rect = System.Drawing.Rectangle.Union( cpage.ClientBounds , myCurrentPage.ClientBounds ); this.OnCurrentPageChanged(); DrawHeadShadow(); } } base.OnXScroll(); }
/// <summary> /// 根据页面位置添加矩形区域转换关系 /// </summary> /// <param name="myTransform">转换列表</param> /// <param name="ForPrint">是否为打印进行填充</param> public virtual void AddPage(PrintPage page, float pageTop, float zoomRate) { //XPageSettings pageSettings = page.PageSettings; System.Drawing.Rectangle rect = System.Drawing.Rectangle.Empty; int leftmargin = (int)(page.ViewLeftMargin * zoomRate); int topmargin = (int)(page.ViewTopMargin * zoomRate); int rightmargin = (int)(page.ViewRightMargin * zoomRate); int bottommargin = (int)(page.ViewBottomMargin * zoomRate); int pagewidth = (int)(page.ViewPaperWidth * zoomRate); int pageheight = (int)(page.ViewPaperHeight * zoomRate); int top = (int)pageTop + topmargin; SimpleRectangleTransform item = null; if (page.HeaderHeight > 0) { // 添加文档页眉视图映射 item = new SimpleRectangleTransform(); item.PageIndex = page.GlobalIndex; item.ContentStyle = PageContentPartyStyle.Header; item.PageObject = page; item.DocumentObject = page.Document; // 映射到文档视图 item.DescRectF = new System.Drawing.RectangleF( 0, 0, page.Width, page.HeaderHeight - 1); top = SetSourceRect( item, zoomRate, leftmargin + page.ClientLeftFix, top); this.Add(item); } // 添加正文文档映射 item = new SimpleRectangleTransform(); item.PageIndex = page.GlobalIndex; item.ContentStyle = PageContentPartyStyle.Body; item.PageObject = page; item.DocumentObject = page.Document; // 映射到文档视图 item.DescRectF = new System.Drawing.RectangleF( 0, page.Top, page.Width, page.Height); top = SetSourceRect( item, zoomRate, leftmargin + page.ClientLeftFix, top); this.Add(item); if (page.FooterHeight > 0) { // 添加页脚文档视图映射 item = new SimpleRectangleTransform(); item.PageIndex = page.GlobalIndex; item.ContentStyle = PageContentPartyStyle.Footer; item.PageObject = page; item.DocumentObject = page.Document; // 映射到文档视图 item.DescRectF = new System.Drawing.RectangleF( 0, page.DocumentHeight - page.FooterHeight + 1, page.Width, page.FooterHeight - 1); SetSourceRect(item, zoomRate, leftmargin, top); rect = item.SourceRect; top = (int)(pageTop + pageheight - bottommargin - rect.Height); item.SourceRectF = new System.Drawing.RectangleF( leftmargin + page.ClientLeftFix, top, rect.Width, rect.Height); this.Add(item); } }
/// <summary> /// 打印指定页面 /// </summary> /// <param name="myPage">页面对象</param> /// <param name="g">绘图操作对象</param> /// <param name="MainClipRect">主剪切矩形</param> /// <param name="UseMargin">是否启用页边距</param> public virtual void DrawPage( PrintPage myPage, System.Drawing.Graphics g, System.Drawing.Rectangle MainClipRect, bool UseMargin) { //XPageSettings pageSettings = myPage.PageSettings; int LeftMargin = 0; int TopMargin = 0; int RightMargin = 0; int BottomMargin = 0; if (UseMargin) { LeftMargin = (int)myPage.ViewLeftMargin; TopMargin = (int)myPage.ViewTopMargin; RightMargin = (int)myPage.ViewRightMargin; BottomMargin = (int)myPage.ViewBottomMargin; } this.OnBeforeDrawPage(myPage, g); IntPtr hdc = g.GetHdc(); DeviceCapsClass dcc = new DeviceCapsClass(hdc); g.ReleaseHdc(); g.PageUnit = myDocument.DocumentGraphicsUnit; System.Drawing.Rectangle ClipRect = System.Drawing.Rectangle.Empty; if (this.strPageHeadText != null) { // 绘制标题文本 g.DrawString( strPageHeadText, System.Windows.Forms.Control.DefaultFont, System.Drawing.Brushes.Red, 20, 20, System.Drawing.StringFormat.GenericDefault); } float printableAreaOffsetX = (float)GraphicsUnitConvert.Convert( myPrintableAreaOffset.X / 100.0, System.Drawing.GraphicsUnit.Inch, myDocument.DocumentGraphicsUnit); float printableAreaOffsetY = (float)GraphicsUnitConvert.Convert( myPrintableAreaOffset.Y / 100.0, System.Drawing.GraphicsUnit.Inch, myDocument.DocumentGraphicsUnit); if (this.bolDrawHead) { // 绘制页眉 if (myPage.HeaderHeight > 0) { g.ResetTransform(); g.ResetClip(); ClipRect = new System.Drawing.Rectangle( 0, 0, myPage.Width, myPage.HeaderHeight); g.ScaleTransform(this.XZoomRate, this.YZoomRate); g.TranslateTransform( LeftMargin - printableAreaOffsetX, TopMargin - printableAreaOffsetY); g.SetClip(new System.Drawing.Rectangle( ClipRect.Left, ClipRect.Top, ClipRect.Width + 1, ClipRect.Height + 1)); PageDocumentPaintEventArgs args = new PageDocumentPaintEventArgs( g, ClipRect, myDocument, myPage, PageContentPartyStyle.Header); args.ContentBounds = ClipRect; args.PageIndex = myPage.GlobalIndex; args.NumberOfPages = this.Pages.Count; args.ContentBounds = ClipRect; myDocument.DrawContent(args); //DesignPaintEventArgs e = new DesignPaintEventArgs( g , ClipRect ); //myDocument.RefreshView( e ); } g.ResetClip(); g.ResetTransform(); } // 绘制页面正文 ClipRect = new System.Drawing.Rectangle( 0, myPage.Top, myPage.Width, myPage.Height); if (!MainClipRect.IsEmpty) { ClipRect = System.Drawing.Rectangle.Intersect(ClipRect, MainClipRect); } if (!ClipRect.IsEmpty) { g.ScaleTransform(this.XZoomRate, this.YZoomRate); g.TranslateTransform( LeftMargin - printableAreaOffsetX, TopMargin - myPage.Top + myPage.HeaderHeight - printableAreaOffsetY); //System.Drawing.Drawing2D.GraphicsPath clipPath = new System.Drawing.Drawing2D.GraphicsPath(); //clipPath.AddRectangle( ClipRect ); //g.SetClip( clipPath ); //g.TranslateTransform( myPages.LeftMargin , myPages.TopMargin - myPage.Top + myPages.HeadHeight ); System.Drawing.RectangleF rect = DrawerUtil.FixClipBounds( g, ClipRect.Left, ClipRect.Top, ClipRect.Width, ClipRect.Height); rect.Offset(-4, -4); rect.Width = rect.Width + 8; rect.Height = rect.Height + 8; g.SetClip(rect); // System.Drawing.RectangleF rect2 = g.ClipBounds ; // if( rect.Top < rect2.Top ) // { // float dy = rect2.Top - rect.Top ; // rect.Y = rect.Y - dy * 2 ; // rect.Height = rect.Height + dy * 4 ; // } // g.SetClip( rect ); PageDocumentPaintEventArgs args = new PageDocumentPaintEventArgs( g, ClipRect, myDocument, myPage, PageContentPartyStyle.Body); args.PageIndex = myPage.GlobalIndex; args.NumberOfPages = this.Pages.Count; args.ContentBounds = ClipRect; myDocument.DrawContent(args); //myDocument.DrawDocument( g , ClipRect ); //DesignPaintEventArgs e = new DesignPaintEventArgs( g , ClipRect ); //myDocument.RefreshView( e ); } if (this.bolDrawFooter) { // 绘制页脚 if (myPage.FooterHeight > 0) { g.ResetClip(); g.ResetTransform(); int documentHeight = myPage.DocumentHeight; ClipRect = new System.Drawing.Rectangle( 0, documentHeight - myPage.FooterHeight, myPage.Width, myPage.FooterHeight); int dy = 0; if (UseMargin) { dy = (int)(myPage.ViewPaperHeight - myPage.ViewBottomMargin); } else { dy = (int)(myPage.ViewPaperHeight - myPage.ViewBottomMargin - myPage.ViewTopMargin); } g.ScaleTransform(this.XZoomRate, this.YZoomRate); g.TranslateTransform( LeftMargin - printableAreaOffsetX, dy - printableAreaOffsetY); g.SetClip(new System.Drawing.Rectangle( ClipRect.Left, ClipRect.Top, ClipRect.Width + 1, ClipRect.Height + 1)); PageDocumentPaintEventArgs args = new PageDocumentPaintEventArgs( g, ClipRect, myDocument, myPage, PageContentPartyStyle.Footer); args.ContentBounds = ClipRect; args.PageIndex = myPage.GlobalIndex; args.NumberOfPages = this.Pages.Count; myDocument.DrawContent(args); //DesignPaintEventArgs e = new DesignPaintEventArgs( g , ClipRect ); //myDocument.RefreshView( e ); } } //if( this.bolDrawFooter ) } //public void DrawPage()
/// <summary> /// 开始输出一个页面前执行的过程 /// </summary> /// <param name="page">页面对象</param> /// <param name="g">图形绘制对象</param> protected virtual void OnBeforeDrawPage( PrintPage page, System.Drawing.Graphics g) { //myDocument.PageIndex = page.GlobalIndex; }
/// <summary> /// 绘制页面框架 /// </summary> /// <param name="myPage">页面对象</param> /// <param name="g">图形绘制对象</param> /// <param name="Focused">该页是否是当前页</param> /// <param name="FillBackGround">是否填充背景</param> protected void DrawPageFrame( PrintPage myPage, System.Drawing.Graphics g, System.Drawing.Rectangle ClipRectangle, bool FillBackGround) { if (myPage == null || _Pages.Contains(myPage) == false) { return; } System.Drawing.Rectangle bounds = myPage.ClientBounds; bounds.Offset(this.AutoScrollPosition); // 绘制页面阴影 //int ShadowSize = 5; //g.FillRectangle(System.Drawing.Brushes.Black, bounds.Right - 1 , bounds.Top + ShadowSize, ShadowSize, bounds.Height-1); //g.FillRectangle(System.Drawing.Brushes.Black , bounds.Left + ShadowSize, bounds.Bottom - 1 , bounds.Width-1, ShadowSize); //System.Drawing.Rectangle ShadowRect = bounds; //ShadowRect.Offset(10 , 10 ); //using (System.Drawing.Pen p = new System.Drawing.Pen( System.Drawing.Color.Gray , 10 )) //{ // g.DrawRectangle(p, ShadowRect); //} PageFrameDrawer drawer = new PageFrameDrawer(); drawer.BorderWidth = 1; drawer.Bounds = bounds; drawer.Margins = myPage.ClientMargins; if (myPage == this.CurrentPage) { if (this.Enabled) // info.Enabled ) { drawer.BorderColor = System.Drawing.ColorTranslator.FromHtml("#EEAA57"); // System.Drawing.Color.Red; drawer.BorderWidth = 3; } else { drawer.BorderColor = System.Drawing.Color.LightGray; drawer.BorderWidth = 3; } } else { drawer.BorderWidth = 3; drawer.BorderColor = System.Drawing.Color.Black; } drawer.BackColor = FillBackGround ? this.PageBackColor : System.Drawing.Color.Transparent; //this.FixedBackground = false; drawer.DrawPageFrame(g, ClipRectangle); //XDesignerDrawer.PageFrameDrawer.DrawPageFrame( // bounds , // this.myClientMargins , // g , // System.Drawing.Rectangle.Empty , // Focused , // FillBackGround ? this.PageBackColor : System.Drawing.Color.Transparent ); }
/// <summary> /// 打印指定页面 /// </summary> /// <param name="myPage">页面对象</param> /// <param name="g">绘图操作对象</param> /// <param name="MainClipRect">主剪切矩形</param> /// <param name="PrintHead">是否打印页眉</param> /// <param name="PrintTail">是否打印页脚</param> protected void OnPaintPage( PrintPage myPage, System.Drawing.Graphics g, System.Drawing.Rectangle MainClipRect, bool DrawHead, bool DrawFooter, PrintPageEventArgs args) { if (PaintPage != null) { PaintPage(this, new EventArgs()); } this.PageDrawer.Document = myPage.Document; this.PageDrawer.Pages = this.Pages; this.PageDrawer.DrawFooter = DrawFooter; this.PageDrawer.DrawHead = DrawHead; if (myPage.PageSettings.AutoFitPageSize) { //// 计算实际的打印区域大小 //IntPtr hdc = g.GetHdc(); //Win32.DeviceCapsClass dcc = new DCSoft.Win32.DeviceCapsClass(hdc); //g.ReleaseHdc(hdc); //float width = ( float )DCSoft.Drawing.GraphicsUnitConvert.Convert(dcc.HORZSIZE * 1.0 , System.Drawing.GraphicsUnit.Millimeter, System.Drawing.GraphicsUnit.Inch) * 100.0f ;// args.PageSettings.PaperSize.Width;// -args.PageSettings.Margins.Left - args.PageSettings.Margins.Right; //float height = ( float) DCSoft.Drawing.GraphicsUnitConvert.Convert(dcc.VERTSIZE * 1.0 , System.Drawing.GraphicsUnit.Millimeter, System.Drawing.GraphicsUnit.Inch) * 100.0f ;// args.PageSettings.PaperSize.Height;// -args.PageSettings.Margins.Top - args.PageSettings.Margins.Bottom; float width = args.PageSettings.Bounds.Width; float height = args.PageSettings.Bounds.Height; //if( args.PageSettings.Landscape ) //{ // float temp = width ; // width = height ; // height = temp ; //} // 计算预计的打印区域大小 float width2 = myPage.PageSettings.PaperWidth; // -myPage.PageSettings.LeftMargin - myPage.PageSettings.RightMargin; float height2 = myPage.PageSettings.PaperHeight; // -myPage.PageSettings.TopMargin - myPage.PageSettings.BottomMargin; if (myPage.PageSettings.Landscape) { float temp = width2; width2 = height2; height2 = temp; } if (Math.Abs((width - width2) / width2) > 0.04 || Math.Abs((height - height2) / height2) > 0.04) { // 预计的打印区域和实际的打印区域出现较大的差别,则进行自动缩放 if (width2 > 0 && height2 > 0) { float rate = Math.Min(width / width2, height / height2); //if (rate < 1) // rate = rate * 0.98f; this.PageDrawer.XZoomRate = rate; this.PageDrawer.YZoomRate = rate; //drawer.XZoomRate = width / width2; //if (drawer.XZoomRate < 1) // drawer.XZoomRate *= 0.98f; //drawer.YZoomRate = height / height2; //if (drawer.YZoomRate < 1) // drawer.YZoomRate *= 0.98f; } } } this.PageDrawer.PrintableAreaOffset = args.PageSettings.PrintableArea.Location; this.PageDrawer.DrawPage(myPage, g, MainClipRect, true); }
/// <summary> /// 获得从0开始的序号 /// </summary> /// <param name="myPage"></param> /// <returns></returns> public int IndexOf(PrintPage myPage) { return(this.InnerList.IndexOf(myPage)); }
/// <summary> /// 已重载:绘制文档内容 /// </summary> /// <param name="e">绘制事件参数</param> protected override void OnPaint(System.Windows.Forms.PaintEventArgs e) { //if (this.DesignMode) { base.OnPaint(e); } if (this.IsUpdating) { return; } System.Drawing.Rectangle clipRect = e.ClipRectangle; clipRect.Height += 1; System.Drawing.Point sp = this.AutoScrollPosition; //int ax = - this.AutoScrollPosition.X ; //int ay = - this.AutoScrollPosition.Y ; this.RefreshScaleTransform(); if (this.PagesTransform == null || this.PagesTransform.Count == 0) { // 没有任何内容可以绘制 return; } if (this.ViewMode == PageViewMode.Normal) { using (SolidBrush b = new SolidBrush(this.PageBackColor)) { e.Graphics.FillRectangle(b, e.ClipRectangle); } SimpleRectangleTransform item = this.PagesTransform[0]; PrintPage myPage = (PrintPage)item.PageObject; Rectangle rect = item.SourceRect; rect.Width = rect.Width + 30; rect = Rectangle.Intersect( clipRect, rect); if (rect.IsEmpty == false) { // 保存状态 System.Drawing.Drawing2D.GraphicsState state2 = e.Graphics.Save(); //try { PaintEventArgs e2 = this.CreatePaintEventArgs(e, item); if (e2 != null) { PageDocumentPaintEventArgs e3 = new PageDocumentPaintEventArgs( e2.Graphics, e2.ClipRectangle, myPage.Document, myPage, item.ContentStyle); e3.ContentBounds = item.DescRect; e3.RenderMode = ContentRenderMode.Paint; e3.PageIndex = myPage.PageIndex; e3.NumberOfPages = this.Pages.Count; //e3.EditMode = this.EditMode; if (myPage.Document != null) { myPage.Document.DrawContent(e3); }//if } } //catch (Exception ext) //{ // System.Console.WriteLine(ext.ToString()); //} // 恢复状态 e.Graphics.Restore(state2); } return; } // MultiPageTransform trans = ( MultiPageTransform )this.Transform; // trans.ClearSourceOffset(); // trans.OffsetSource( sp.X , sp.Y , true ); System.Drawing.Graphics g = e.Graphics; //System.Drawing.Drawing2D.GraphicsState stateBack = e.Graphics.Save(); foreach (PrintPage myPage in this.Pages) { System.Drawing.Rectangle ClientBounds = myPage.ClientBounds; ClientBounds.Offset(sp); ClientBounds.Width = ClientBounds.Width + 20; //if( clipRect.Top <= ClientBounds.Bottom + 5 // && clipRect.Bottom >= ClientBounds.Top ) if (clipRect.IntersectsWith( new Rectangle( ClientBounds.Left, ClientBounds.Top, ClientBounds.Width + 5, ClientBounds.Height + 5))) { //this.SetPageIndex( myPage.Index ); //e.Graphics.Restore(stateBack); //e.Graphics.ResetClip(); DrawPageFrame( myPage, e.Graphics, clipRect, true); for (int iCount = trans.Count - 1; iCount >= 0; iCount--) { SimpleRectangleTransform item = trans[iCount]; if (item.Visible && item.PageObject == myPage) { // 显示页眉页脚标记文本 if (item.ContentStyle == PageContentPartyStyle.Header) { if (this.HeaderFooterFlagVisible == HeaderFooterFlagVisible.Header || this.HeaderFooterFlagVisible == HeaderFooterFlagVisible.HeaderFooter) { // 绘制页眉标记 //e.Graphics.Restore(stateBack); DrawHeaderFooterFlag( PrintingResources.Header, item.PartialAreaSourceBounds, e.Graphics); } } else if (item.ContentStyle == PageContentPartyStyle.Footer) { if (this.HeaderFooterFlagVisible == HeaderFooterFlagVisible.Footer || this.HeaderFooterFlagVisible == HeaderFooterFlagVisible.HeaderFooter) { // 绘制页脚标记 //e.Graphics.Restore(stateBack); DrawHeaderFooterFlag( PrintingResources.Footer, item.PartialAreaSourceBounds, e.Graphics); } } Rectangle rect = item.SourceRect; rect = Rectangle.Intersect( clipRect, rect); if (rect.IsEmpty == false) { System.Drawing.Drawing2D.GraphicsState state2 = e.Graphics.Save(); PaintEventArgs e2 = this.CreatePaintEventArgs(e, item); if (e2 != null) { PageDocumentPaintEventArgs e3 = new PageDocumentPaintEventArgs( e2.Graphics, e2.ClipRectangle, myPage.Document, myPage, item.ContentStyle); e3.ContentBounds = item.DescRect; e3.RenderMode = ContentRenderMode.Paint; e3.PageIndex = myPage.PageIndex; e3.NumberOfPages = this.Pages.Count; //e3.EditMode = this.EditMode; if (myPage.Document != null) { myPage.Document.DrawContent(e3); }//if } e.Graphics.Restore(state2); if (item.Enable == false) { // 若区域无效则用白色半透明进行覆盖,以作标记 using (System.Drawing.SolidBrush maskBrush = new SolidBrush(Color.FromArgb(140, this.PageBackColor))) { e.Graphics.FillRectangle( maskBrush, rect.Left, rect.Top, rect.Width + 2, rect.Height + 2); } } } //if // ClipRect.Height -= 1; } } //foreach } //if } //foreach DrawHeadShadow(); //base.OnPaint( e ); //e.Graphics.Flush(System.Drawing.Drawing2D.FlushIntention.Sync); //System.Threading.Thread.Sleep(100); }
/// <summary> /// 判断是否存在指定的页对象 /// </summary> /// <param name="page">页对象</param> /// <returns>是否存在页对象</returns> public bool Contains(PrintPage page) { return(this.List.Contains(page)); }
/// <summary> /// 删除指定页 /// </summary> /// <param name="myPage"></param> public void Remove(PrintPage myPage) { this.List.Remove(myPage); }
/// <summary> /// 添加页对象 /// </summary> /// <param name="myPage"></param> public int Add(PrintPage myPage) { return(this.List.Add(myPage)); //if( ! this.InnerList.Contains( myPage ) ) // this.InnerList.Add( myPage ); }