Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to make a web page WEB printing control

2025-04-10 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

< N_PageHeith){isFillRowNum++;}if (isFillRowNum >

) isCanFillRow = true;} # endregion#region first draw the previous page of supplementary cells if (CurPageNum >) {PagingItem prePage = GetPageItem (CurPageNum -); / / previous page if (prePage! = null) {foreach (PagingMakeUp tmMk in prePage.MakeupList) {/ / draw supplementary cells (unfinished cells on the previous page) DrawTD (g, tmMk.MakeupCell, offsetX, offsetY, true, tmMk.MakeupHeight, false) Endregion#region next draws the current page cell / / then draws the current page cell for (int ii =; ii)

< nowPage.IndexList.Count; ii++){// 先绘制 TD CELL 单元格Row rowTR = GetRow(nowPage.IndexList[ii]);#region 执行补行if (isCanFillRow == true && rowTR.RowType.ToLower().Trim() == "f") // 需要补行 行标志为F 表尾前进行补充空行{Row fillRow = new Row();if (ii == )fillRow = rowTR;elsefillRow = GetRow(nowPage.IndexList[ii - ]);if (fillRow != null) // 绘制自动补充的空行单元格{// 开始补充空行 for (int fi = ; fi ){DrawLine(g, offsetX, offsetY, offsetX, offsetY + .F * Zoom); // 最左边竖线DrawLine(g, offsetX, offsetY + .F * Zoom, offsetX + fillTdCell.RectX, offsetY + .F * Zoom);}bcFlag = false;}DrawTD(g, fillTdCell, offsetX, offsetY, false, , true);}// 再将偏移量+行号 补充的行高全部为pxoffsetY += * Zoom;}}isFillFlag = true;}#endregion#region 正常绘制foreach (Cell td in rowTR.RowCells){DrawTD(g, td, offsetX, offsetY, false, , false);}// 再将偏移量+行号offsetY += rowTR.RowHeight;#endregion}// 判定是否补过;没有补充过,则在最后进行补充空行if ((isCanFillRow == true) && (isFillFlag == false) && (nowPage.IndexList.Count >

) {Row fillRow = GetRow (nowPage.IndexList.Count -]); if (fillRow! = null) / / draw auto-replenished blank line cells {/ / start filling blank lines for (int fi =; fi) {DrawLine (g, offsetX, offsetY, offsetX, offsetY + .F * Zoom); / / leftmost vertical bar DrawLine (g, offsetX, offsetY + .F * Zoom, offsetX + fillTdCell.RectX, offsetY + .F * Zoom);} newFlag = false } DrawTD (g, fillTdCell, offsetX, offsetY, false, true);} offsetY + = * Zoom; / / then add the line height of offset + line number to px}} # endregionif (CurPageNum

< AllPageNum){isMorePage = true; // 还有下页CurPageNum++; // 页码增加}}return isMorePage;}/// /// 绘制单元格/// /// 绘图对象/// 单元格/// X偏移量/// Y坐标值/// 是否补充单元格/// 补充单元格高度/// 自动补行的单元格private void DrawTD(Graphics g, Cell tdCell, float setX, float setY, bool isMakeup, float mkH, bool fillCell){#region 参数变量Pen pen;Brush brush;// 获取单元格绘制坐标矩形信息float tdX = tdCell.RectX + setX;float tdY = setY;float tdW = tdCell.RectW;float tdH = ;if (fillCell){tdH = * Zoom; // 自动补行的单元格的高度固定为px}else{if (isMakeup) // 补充单元格{tdH = mkH;tdY = tdY + HeadPix; // 如果是补充单元格,则此单元格的Y坐标:如果每页打印标题或表头,则Y坐标 需要下移 HeadPix}else // 实际单元格{tdH = tdCell.RectH;}if (tdCell.RowSpan >

) / / determine whether the cell height exceeds the bottom line {tdH = Calc_CellOverHeight (tdCell, tdY, tdH);}} # endregion#region draws the background / / fill color brush = new SolidBrush (tdCell.BackColor); g.FillRectangle (brush, tdX + .f * Zoom, tdY + .f * Zoom, tdW-.f * Zoom, tdH-.f * Zoom) # endregion#region draw border / / left border if (tdCell.LeftBorder.LineWidth >) {pen = new Pen (tdCell.LeftBorder.LineColor); pen.DashStyle = tdCell.LeftBorder.LineDash;pen.Width = tdCell.LeftBorder.LineWidth;g.DrawLine (pen, tdX, tdY, tdX, tdY + tdH);} / / Top border if (tdCell.TopBorder.LineWidth >) {pen = new Pen (tdCell.TopBorder.LineColor); pen.DashStyle = tdCell.TopBorder.LineDash;pen.Width = tdCell.TopBorder.LineWidth G.DrawLine (pen, tdX, tdY, tdX + tdW, tdY);} / / right border line if (tdCell.RightBorder.LineWidth >) {pen = new Pen (tdCell.RightBorder.LineColor); pen.DashStyle = tdCell.RightBorder.LineDash;pen.Width = tdCell.RightBorder.LineWidth;g.DrawLine (pen, tdX + tdW, tdY, tdX + tdW, tdY + tdH);} / / bottom border if (tdCell.BottomBorder.LineWidth >) {pen = new Pen (tdCell.BottomBorder.LineColor); pen.DashStyle = tdCell.BottomBorder.LineDash Pen.Width = tdCell.BottomBorder.LineWidth;g.DrawLine (pen, tdX, tdY + tdH, tdX + tdW, tdY + tdH);} # endregion#region draw text if (! fillCell) {RectangleF rect = new RectangleF (tdX, tdY, tdW, tdH); if (tdCell.IsImage) {this.DrawImg (g, rect, tdCell.ImageUrl);} else {brush = new SolidBrush (tdCell.FontColor); this.DrawStr (g, rect, brush, tdCell.CellFont, tdCell.strFormat, tdCell.Value) }} # endregion} / when drawing a string / overflow Newline reduced character / font must not be less than / drawing object / / text area / text stroke / text font / text format / text character / private void DrawStr (Graphics g, RectangleF strRect, Brush strBrush, Font strFont, StringFormat strFormat, string strValue) {/ / report setting: character overflow does not handle if (! this.IsOverFlow) {g.DrawString (strValue) StrFont, strBrush, strRect, strFormat) } else / / need to deal with {/ / measure the width and height of the font, you will find that the error is very large, if you measure one by one, the error is too large, so here is a simple way to deal with SizeF sf = g.MeasureString (strValue, strFont); / / this way of measurement error is very large, if if (strRect.Width > sf.Width) {g.DrawString (strValue, strFont, strBrush, strRect, strFormat) } else {/ / calculate whether the full height of characters after line wrapping satisfies int maxLines =; / / calculate the maximum number of lines printed in the current character's current font maxLines = (int) Math.Ceiling ((double) sf.Width / (double) strRect.Width); if (strRect.Height > = maxLines * sf.Height) {g.DrawString (strValue, strFont, strBrush, strRect, strFormat);} else {float tmScale = strRect.Height / (maxLines * sf.Height) Font tmNewFont = new Font (strFont.Name, strFont.Size * tmScale, strFont.Style, GraphicsUnit.Point); g.DrawString (strValue, tmNewFont, strBrush, strRect, strFormat);} / draw Base picture stream string into picture and draw / private void DrawImg (Graphics g, RectangleF strRect, string baseImg) {if (baseImg.Trim () = ") return String imgStr = baseImg.Replace ("data:image/gif;base,", ") .Trim (); if (imgStr = =") return;// generates pictures try {MemoryStream stream = new MemoryStream (Convert.FromBaseString (imgStr)); Bitmap picImg = new Bitmap (stream); RectangleF imgRectF = new RectangleF (f, f, (float) picImg.Width, (float) picImg.Height) / / original picture rectangle RectangleF newRectF = new RectangleF (strRect.X + f, strRect.Y + f, (float) strRect.Width-f, (float) strRect.Height-f); / / draw picture rectangle g.DrawImage (picImg, newRectF, imgRectF, GraphicsUnit.Pixel); / / draw zoom picture stream.Close ();} catch {return }} / draw lines / drawing object / / start X _ float end_X / end X _ Yprivate void DrawLine (Graphics g, float start_X, float start_Y, float end_X, float end_Y) {Pen linePen = new Pen (Color.Black, .f); linePen.DashStyle = DashStyle.Solid;g.DrawLine (linePen, start_X, start_Y, end_X, end_Y) } private float ChangeUnit (float vSize) {return (vSize * f / f * f / f);} / get row object / private Row GetRow (int rowIndex) {foreach (Row retRow in _ rowsList) {if (retRow.RowIndex = = rowIndex) return retRow;} return null } / get the paging page / page number / private PagingItem GetPageItem (int pNo) {foreach (PagingItem retPItem in PageList) {if (retPItem.PageNum = = pNo) return retPItem;} return null } / calculate the drawing height / determine and calculate whether the cell height exceeds the bottom line of all row heights on the current page / H current height / private float Calc_CellOverHeight (Cell mCell, float mY, float mH) {float returnHeight =; / / return height float tm_AllTrHeight = GetThisPageDataRowsHeight () / / height of all data rows in the current page float tm_RealY =; / / relative maximum Y value float tm_AbsY =; / / actual maximum Y value float tm_OverPlus =; / / remaining cell height tm_RealY = mY + mH; / / actual maximum Y value if (IsAllPrintFoot) / / print footer tm_AbsY = ReptRect.Y + (tm_AllTrHeight-FootPix) per page / / need to subtract the footer height elsetm_AbsY = tm_AllTrHeight + ReptRect.Y;if (tm_RealY > tm_AbsY) {returnHeight = tm_AbsY-mY; / / actual maximum height of the current page-current Y coordinate value of the cell = return the height of the cell to be drawn on this page tm_OverPlus = mH-returnHeight / / current height-the height to be drawn on the current page of the cell = the supplementary height to be drawn on the next page / / add the current cell to the back page to add PagingItem nPageItem = GetPageItem (CurPageNum); PagingMakeUp nMakeUp = new PagingMakeUp (); nMakeUp.MakeupCell = mCell;nMakeUp.MakeupHeight = tm_OverPlus;nPageItem.MakeupList.Add (nMakeUp);} else {returnHeight = mH;} return returnHeight } / private float GetThisPageDataRowsHeight () {float retHeight =; PagingItem oThisPage = GetPageItem (CurPageNum); / / current page foreach (int oRowIndex in oThisPage.IndexList) {Row oThisRow = GetRow (oRowIndex); retHeight + = oThisRow.RowHeight;} return retHeight } / get the height of the row to which an item belongs on the page / Page object / the serial number of an item in the row array on this page / private float GetThisPageOneRowHeight (PagingItem itemPage, int itemIndex) {float retHeight =; if (itemIndex)

< itemPage.IndexList.Count && itemIndex >

=) {Row oThisRow = GetRow (itemPage. IndexList [itemIndex]); retHeight = oThisRow.RowHeight;} return retHeight;} # endregion} 3, PagingCalc paging calculation class using System;using System.Collections.Generic;using System.Text;using System.Drawing;namespace E_Print {/ public class PagingCalc {# region private variable / table region / private RectangleF _ tableRect;/// report rowset / private List _ rowsList / whether to print the header / private bool _ isAllPrintTitle;/// whether to print the header per page / private bool _ isAllPrintHead;/// whether to print the footer / private bool _ isAllPrintFoot;/// header rowset / private List TitleList;/// header rowset / private List HForeList;/// header rowset / private List HeadList / data rowset / private List DataList;/// footer rowset / private List FootList;/// print header per page + header height / private float _ myHeadPix;/// print footer height per page / private float _ myFootPix;#endregion#region constructor / public PagingCalc () {_ tableRect = new RectangleF () _ rowsList = new List (); _ isAllPrintTitle = false;_isAllPrintHead = false;_isAllPrintFoot = false;TitleList = new List (); HForeList = new List (); HeadList = new List (); DataList = new List (); FootList = new List (); _ myHeadPix =; _ myFootPix =;} # endregion#region attribute method / get-- set-- Table area / public RectangleF TableRect {get {return _ tableRect;} set {_ tableRect = value } / get-- Settings-- Table rowset / public List RowsList {get {return _ rowsList;} set {_ rowsList = value;}} / get-- whether the title / public bool IsAllPrintTitle {get {return _ isAllPrintTitle;} set {_ isAllPrintTitle = value is printed per page. }} / get-- set-- whether to print header / public bool IsAllPrintHead {get {return _ isAllPrintHead;} set {_ isAllPrintHead = value;}} / get-- set-- whether to print footer / public bool IsAllPrintFoot {get {return _ isAllPrintFoot;} set {_ isAllPrintFoot = value per page } / get-- set-- print title per page + header height / public float MyHeadPix {get {return _ myHeadPix;} set {_ myHeadPix = value;}} / get-- setting-- print table tail height per page / public float MyFootPix {get {return _ myFootPix;} set {_ myFootPix = value }} # endregion#region calculation method / public List CalcPages () {List retPages = new List (); / / No paging if (Get_TableAllHeight ())

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report