/// <summary> /// 更新当前页面对象 /// </summary> /// <returns>操作是否改变了当前页面对象</returns> protected bool UpdateCurrentPage() { if (myPages != 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 myPages) { 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); }
protected override void RefreshScaleTransform() { MultiPageTransform trans = (MultiPageTransform)this.myTransform; intGraphicsUnit = myPages.GraphicsUnit; trans.Rate = GraphicsUnitConvert.GetRate(intGraphicsUnit, System.Drawing.GraphicsUnit.Pixel); //float rate = ( float )( 1.0 / this.ClientToViewXRate ); //trans.Pages = myPages ; //trans.Refresh( rate , this.intPageSpacing ); System.Drawing.Point sp = this.AutoScrollPosition; trans.ClearSourceOffset(); trans.OffsetSource(sp.X, sp.Y, true); // myClientMargins = new System.Drawing.Printing.Margins( // ( int ) ( myPages.LeftMargin * rate ), // ( int ) ( myPages.RightMargin * rate ) , // ( int ) ( myPages.TopMargin * rate ), // ( int ) ( myPages.BottomMargin * rate )); // // myClientPageSize = new System.Drawing.Size( // ( int) ( myPages.PaperWidth * rate ) , // ( int ) ( myPages.PaperHeight * rate )); }
/// <summary> /// 根据指定坐标的位置获得选中的坐标 /// </summary> /// <param name="x"></param> /// <param name="y"></param> /// <returns></returns> protected Point GetSelectAreaPoint(int x, int y) { MultiPageTransform trans = (MultiPageTransform)this.myTransform; if (trans.ContainsSourcePoint(x, y)) { Point p = this.myTransform.TransformPoint(x, y); return(p); } return(Point.Empty); }
/// <summary> /// 根据指定坐标的位置获得续打位置 /// </summary> /// <param name="x">X坐标值</param> /// <param name="y">Y坐标值</param> /// <returns>续打位置</returns> protected int GetJumpPrintPosition(int x, int y) { MultiPageTransform trans = (MultiPageTransform)this.myTransform; if (trans.ContainsSourcePoint(x, y)) { int pos = this.myTransform.TransformPoint(x, y).Y; if (pos >= 0) { return(pos); } } return(0); }
/// <summary> /// 绘制续打区域 /// </summary> /// <param name="g">图形绘制对象</param> /// <param name="ClipRectangle">剪切矩形</param> /// <param name="Position">续打位置</param> /// <param name="FillColor">填充色</param> protected void DrawJumpPrintArea( System.Drawing.Graphics g, System.Drawing.Rectangle ClipRectangle, int Position, System.Drawing.Color FillColor) { MultiPageTransform trans = (MultiPageTransform)this.myTransform; int pos = trans.UnTransformY(Position); if (pos >= 0) { System.Drawing.Rectangle rect = new System.Drawing.Rectangle( 0, 0, this.ClientSize.Width, pos); System.Drawing.Rectangle rect2 = ClipRectangle; if (ClipRectangle.IsEmpty) { rect2 = rect; } else { rect2 = System.Drawing.Rectangle.Intersect(rect, rect2); } if (!rect2.IsEmpty) { g.ResetClip(); g.PageUnit = System.Drawing.GraphicsUnit.Pixel; g.ResetTransform(); using (System.Drawing.SolidBrush b = new System.Drawing.SolidBrush(FillColor)) { g.FillRectangle(b, rect2); } using (System.Drawing.Pen p = new System.Drawing.Pen(System.Drawing.Color.Blue, 2)) { g.DrawLine( p, 0, rect.Bottom - 1, this.ClientSize.Width, rect.Bottom - 1); } } } }
/// <summary> /// 绘制选中区域 Add by wwj 2012-04-17 /// </summary> /// <param name="g"></param> /// <param name="clipRectangle"></param> /// <param name="leftTopPoint"></param> /// <param name="rightBottomPoint"></param> /// <param name="FillColor"></param> protected void DrawSelectAreaPrint(System.Drawing.Graphics g, System.Drawing.Rectangle clipRectangle, Point leftTopPoint, Point rightBottomPoint, System.Drawing.Color FillColor) { MultiPageTransform trans = (MultiPageTransform)this.myTransform; //由于leftTopPoint代表鼠标按下的Location, rightBottomPoint代表鼠标弹起的location //所以需要重新调整leftTopPoint与rightBottomPoint的位置 Point tempPoint = leftTopPoint; if (leftTopPoint.Y > rightBottomPoint.Y) { leftTopPoint = rightBottomPoint; rightBottomPoint = tempPoint; } tempPoint = rightBottomPoint; if (leftTopPoint.X > rightBottomPoint.X) { rightBottomPoint.X = leftTopPoint.X; leftTopPoint.X = tempPoint.X; } leftTopPoint = trans.UnTransformPoint(leftTopPoint); rightBottomPoint = trans.UnTransformPoint(rightBottomPoint); if (true)//表示整行选中 { leftTopPoint.X = 0; rightBottomPoint.X = this.ClientSize.Width; } if (leftTopPoint != Point.Empty && rightBottomPoint != Point.Empty) { Rectangle rect = new Rectangle(leftTopPoint.X, leftTopPoint.Y, rightBottomPoint.X - leftTopPoint.X, rightBottomPoint.Y - leftTopPoint.Y); g.ResetClip(); g.PageUnit = System.Drawing.GraphicsUnit.Pixel; g.ResetTransform(); using (System.Drawing.SolidBrush b = new System.Drawing.SolidBrush(FillColor)) { g.FillRectangle(b, rect); } } }
/// <summary> /// 已重载:绘制文档内容 /// </summary> /// <param name="e">绘制事件参数</param> protected override void OnPaint(System.Windows.Forms.PaintEventArgs e) { if (myUpdateLock.Updating) { return; } System.Drawing.Rectangle ClipRect = e.ClipRectangle; System.Drawing.Point sp = this.AutoScrollPosition; //int ax = - this.AutoScrollPosition.X ; //int ay = - this.AutoScrollPosition.Y ; this.RefreshScaleTransform(); // MultiPageTransform trans = (MultiPageTransform)this.myTransform; // trans.ClearSourceOffset(); // trans.OffsetSource( sp.X , sp.Y , true ); System.Drawing.Graphics g = e.Graphics; foreach (PrintPage myPage in myPages) { System.Drawing.Rectangle ClientBounds = myPage.ClientBounds; ClientBounds.Offset(sp); if (ClientBounds.IntersectsWith(ClipRect)) { this.SetPageIndex(myPage.Index); System.Drawing.Drawing2D.GraphicsState state = e.Graphics.Save(); e.Graphics.ResetTransform(); e.Graphics.PageUnit = System.Drawing.GraphicsUnit.Pixel; e.Graphics.ResetClip(); PageFrameDrawer pfdraw = new PageFrameDrawer(); pfdraw.PageHeaderHeight = (int)(MeasureConvert.DocumentToMillimeter((double)this.myPages.HeadHeight) * 3.776); pfdraw.PageFooterHeight = (int)(MeasureConvert.DocumentToMillimeter((double)this.myPages.FooterHeight) * 3.776); pfdraw.BackColor = this.PageBackColor; pfdraw.DrawTopMargin = this.drawtopmargin; pfdraw.DrawBottomMargin = this.drawbottommargin; pfdraw.DrawPageFrame( ClientBounds, this.myClientMargins, e.Graphics, ClipRect, myPage == this.myCurrentPage, true); e.Graphics.Restore(state); foreach (SimpleRectangleTransform item in trans) { if (item.Visible && item.Tag == myPage) { System.Drawing.Rectangle rect = System.Drawing.Rectangle.Intersect( e.ClipRectangle, item.SourceRect); if (!rect.IsEmpty) { TransformPaint(e, item); } } } } } base.OnPaint(e); }
// // private void UpdateTransform() // { // float rate = ( float )( 1.0 / this.ClientToViewXRate ); // MultiPageTransform trans = ( MultiPageTransform ) this.myTransform ; // trans.Pages = myPages ; // trans.Refresh( rate , this.intPageSpacing ); // } /// <summary> /// 根据分页信息更新页面排布 /// </summary> public virtual void UpdatePages() { if (Common.StackTraceHelper.CheckRecursion()) { return; } float rate = (float)(1.0 / this.ClientToViewXRate); System.Drawing.Size size = new System.Drawing.Size( (int)(myPages.PaperWidth * rate), (int)(myPages.PaperHeight * rate)); System.Drawing.Size TotalSize = new System.Drawing.Size( size.Width + this.intPageSpacing * 2, (size.Height + this.intPageSpacing) * myPages.Count + this.intPageSpacing); if (this.AutoScrollMinSize.Equals(TotalSize) == false) { this.AutoScrollMinSize = TotalSize; } MultiPageTransform trans = (MultiPageTransform)this.myTransform; base.intGraphicsUnit = myPages.GraphicsUnit; trans.Pages = myPages; trans.Refresh(rate, this.intPageSpacing); myClientMargins = new System.Drawing.Printing.Margins( (int)(myPages.LeftMargin * rate), (int)(myPages.RightMargin * rate), (int)(myPages.TopMargin * rate), (int)(myPages.BottomMargin * rate)); myClientPageSize = new System.Drawing.Size( (int)(myPages.PaperWidth * rate), (int)(myPages.PaperHeight * rate)); int ClientWidth = this.ClientSize.Width; int x = 0; if (ClientWidth <= TotalSize.Width) { x = this.intPageSpacing; } else { x = (ClientWidth - TotalSize.Width) / 2 + intPageSpacing; } trans.OffsetSource(x, 0, false); this.RefreshScaleTransform(); System.Drawing.Rectangle rect = System.Drawing.Rectangle.Empty; for (int iCount = 0; iCount < myPages.Count; iCount++) { rect.X = x; rect.Y = (size.Height + this.intPageSpacing) * iCount + this.intPageSpacing; rect.Width = size.Width; rect.Height = size.Height; myPages[iCount].ClientBounds = rect; } this.UpdateCurrentPage(); }