static private void PrintPageEvent (object sender, PrintPageEventArgs e) { float left = e.MarginBounds.Left; float top = e.MarginBounds.Top; Font font = new Font ("Arial", 10); e.Graphics.DrawString("This a sample with font " + font.Name + " size:" + font.Size, font, new SolidBrush (Color.Red), left, top); font = new Font ("Verdana", 16); e.Graphics.DrawString ("This a sample with font " + font.Name + " size:" + font.Size, font, new SolidBrush (Color.Blue), left, top + 50); font = new Font ("Verdana", 22); e.Graphics.DrawString ("This a sample with font " + font.Name + " size:" + font.Size, font, new SolidBrush (Color.Black), left, top + 150); font = new Font (FontFamily.GenericMonospace, 14); e.Graphics.DrawString ("This a sample with font " + font.Name + " size:" + font.Size, font, new SolidBrush (Color.Black), left, top + 250); font = new Font ("Arial", 48); e.Graphics.DrawString ("Font " + font.Name + " size:" + font.Size, font, new SolidBrush (Color.Red), left, top + 300); font = new Font ("Times New Roman", 32); e.Graphics.DrawString ("Another sample font " + font.Name + " size:" + font.Size, font, new SolidBrush (Color.Black), left, top + 500); font = new Font (FontFamily.GenericSansSerif, 8); e.Graphics.DrawString ("Another sample font " + font.Name + " size:" + font.Size, font, new SolidBrush (Color.Blue), left, top + 900); e.HasMorePages = false; }
protected override void OnPrintPage(PrintPageEventArgs e) { base.OnPrintPage(e); Stream pageToPrint = m_pages[m_currentPage]; pageToPrint.Position = 0; // Load each page into a Metafile to draw it. using (Metafile pageMetaFile = new Metafile(pageToPrint)) { Rectangle adjustedRect = new Rectangle( e.PageBounds.Left - (int)e.PageSettings.HardMarginX, e.PageBounds.Top - (int)e.PageSettings.HardMarginY, e.PageBounds.Width, e.PageBounds.Height); // Draw a white background for the report e.Graphics.FillRectangle(Brushes.White, adjustedRect); // Draw the report content e.Graphics.DrawImage(pageMetaFile, adjustedRect); // Prepare for next page. Make sure we haven't hit the end. m_currentPage++; e.HasMorePages = m_currentPage < m_pages.Count; } }
protected override void OnPrintPage(PrintPageEventArgs e) { if (this.PrinterSettings.PrintRange == System.Drawing.Printing.PrintRange.SomePages) { while (++_page < this.PrinterSettings.FromPage) { // Fake the pages that need to be skipped by printing them to a Metafile IntPtr hDev = e.Graphics.GetHdc(); try { using (var mf = new Metafile(hDev, e.PageBounds)) using (var gr = Graphics.FromImage(mf)) { var ppe = new PrintPageEventArgs(gr, e.MarginBounds, e.PageBounds, e.PageSettings); base.OnPrintPage(ppe); } } finally { e.Graphics.ReleaseHdc(hDev); } } // Print the real page base.OnPrintPage(e); // No need to continue past PageTo if (this.PrinterSettings.ToPage > 0 && _page >= this.PrinterSettings.ToPage) e.HasMorePages = false; } else { base.OnPrintPage(e); } }
void PrintDocumentOnPrintPage(object obj, PrintPageEventArgs ppea) { Graphics grfx = ppea.Graphics; SizeF sizef = grfx.VisibleClipBounds.Size; DoPage(grfx, Color.Black, (int)sizef.Width, (int)sizef.Height); }
static private void PrintPageEvent (object sender, PrintPageEventArgs e) { float lines_page, y; int count = 0; float left = e.MarginBounds.Left; float top = e.MarginBounds.Top; String line = null; Font font = new Font ("Arial", 10); float font_height = font.GetHeight (e.Graphics); lines_page = e.MarginBounds.Height / font_height; while (count < lines_page) { line = stream.ReadLine (); if (line == null) break; y = top + (count * font_height); e.Graphics.DrawString (line, font, Brushes.Black, left, y, new StringFormat()); count++; } if (line != null) e.HasMorePages = true; else e.HasMorePages = false; }
// The PrintPage event is raised for each page to be printed. private void pd_PrintPage(object sender, PrintPageEventArgs ev) { float linesPerPage = 0; float yPos = 0; int count = 0; float leftMargin = ev.MarginBounds.Left; float topMargin = ev.MarginBounds.Top; String line = null; // Calculate the number of lines per page. linesPerPage = ev.MarginBounds.Height / printFont.GetHeight(ev.Graphics); // Iterate over the file, printing each line. while (count < linesPerPage && ( ( line = streamToPrint.ReadLine() ) != null )) { yPos = topMargin + ( count * printFont.GetHeight(ev.Graphics) ); ev.Graphics.DrawString(line, printFont, Brushes.Black, leftMargin, yPos, new StringFormat()); count++; } // If more lines exist, print another page. if (line != null) ev.HasMorePages = true; else ev.HasMorePages = false; }
static void doc_PrintPage(object sender, PrintPageEventArgs e) { // Create the output format outputFormatObj of = new outputFormatObj("CAIRO/WINGDIPRINT", "cairowinGDIPrint"); map.appendOutputFormat(of); map.selectOutputFormat("cairowinGDIPrint"); map.resolution = e.Graphics.DpiX; Console.WriteLine("map resolution = " + map.resolution.ToString() + "DPI defresolution = " + map.defresolution.ToString() + " DPI"); // Calculating the desired image size to cover the entire area; map.width = Convert.ToInt32(e.PageBounds.Width * e.Graphics.DpiX / 100); map.height = Convert.ToInt32(e.PageBounds.Height * e.Graphics.DpiY / 100); Console.WriteLine("map size = " + map.width.ToString() + " * " + map.height.ToString() + " pixels"); IntPtr hdc = e.Graphics.GetHdc(); try { // Attach the device to the outputformat for drawing of.attachDevice(hdc); // Drawing directly to the GDI context using (imageObj image = map.draw()) { }; } finally { of.attachDevice(IntPtr.Zero); e.Graphics.ReleaseHdc(hdc); } e.HasMorePages = false; }
private void PrintPage(object sender, PrintPageEventArgs ev) { Metafile pageImage = new Metafile(m_streams[m_currentPageIndex]); ev.Graphics.DrawImage(pageImage, ev.PageBounds); m_currentPageIndex++; ev.HasMorePages = (m_currentPageIndex < m_streams.Count); }
void PrintDocumentOnPrintPage(object obj, PrintPageEventArgs ppea) { Graphics grfx = ppea.Graphics; grfx.DrawString(Text, Font, Brushes.Black, 0, 0); SizeF sizef = grfx.MeasureString(Text, Font); grfx.DrawLine(Pens.Black, sizef.ToPointF(), grfx.VisibleClipBounds.Size.ToPointF()); }
void PrintDocument_PrintPage (object sender, PrintPageEventArgs e) { using (Pen linePen = new Pen (Color.Black, 1f)) { e.Graphics.DrawLine (linePen, 20, 20, 160, 20); e.Graphics.DrawLine (linePen, 20, 40, 160, 40); } using (SolidBrush stringBrush = new SolidBrush (Color.Black)) { e.Graphics.DrawString ("This is a test string.", new Font (FontFamily.GenericSansSerif, 12f), stringBrush, new PointF (20f, 20f)); } }
protected override void OnPrintPage(PrintPageEventArgs e) { CallMethod(_documents[_docIndex], "OnPrintPage", e); base.OnPrintPage(e); if (e.Cancel) return; if (!e.HasMorePages) { CallMethod(_documents[_docIndex], "OnEndPrint", _args); if (_args.Cancel) return; _docIndex++; } }
protected override void OnPrintPage (PrintPageEventArgs e) { base.OnPrintPage (e); Graphics g = e.Graphics; Matrix mx = g.Transform; _matrix = mx; RectangleF rec = g.ClipBounds; if (rec == RectangleF.Empty) Environment.Exit (10); e.HasMorePages = false; e.Cancel = true; }
// The method that calls all other functions public bool DrawDataGridView(PrintPageEventArgs e) { try { drawHeader(e); bool bContinue = drawRows(e); if (_printPageNumbers) drawFooter(e); return bContinue; } catch (Exception ex) { MessageBox.Show("Operation failed: " + ex.Message.ToString(), Application.ProductName + " - Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return false; } }
private void drawFooter(PrintPageEventArgs e) { var pageWidth = _printDocument.DefaultPageSettings.PaperSize.Width; _pageNumber++; string PageString = "Page " + _pageNumber.ToString(); StringFormat PageStringFormat = new StringFormat(); PageStringFormat.Trimming = StringTrimming.Word; PageStringFormat.FormatFlags = StringFormatFlags.NoWrap | StringFormatFlags.LineLimit | StringFormatFlags.NoClip; PageStringFormat.Alignment = StringAlignment.Far; Font PageStringFont = new Font("Ariel", 8, FontStyle.Regular, GraphicsUnit.Point); RectangleF PageStringRectangle = new RectangleF((float)e.MarginBounds.Right, e.MarginBounds.Bottom, (float)pageWidth - (float)e.MarginBounds.Right - (float)e.MarginBounds.Left, e.Graphics.MeasureString(PageString, PageStringFont).Height); e.Graphics.DrawString(PageString, PageStringFont, new SolidBrush(Color.Black), PageStringRectangle, PageStringFormat); }
protected override void OnPrintPage(PrintPageEventArgs e) { CallMethod(_documents[_docIndex], "OnPrintPage", e); base.OnPrintPage(e); if (e.Cancel) return; if (!e.HasMorePages) { CallMethod(_documents[_docIndex], "OnEndPrint", _args); if (_args.Cancel) return; _docIndex++; // increments the current document index if (_docIndex < _documents.Length) { // says that it has more pages (in others documents) e.HasMorePages = true; CallMethod(_documents[_docIndex], "OnBeginPrint", _args); } } }
//// Para imprimir um unico boleto //void pDoc_PrintPageUnico(object sender, PrintPageEventArgs e) //{ // blt.PrintType = PrintTypes.Documet; // blt.Print(e.Graphics); //} // Para imprimir uma serie de boletos onde os dados estão vindo de um datatable void pDoc_PrintPageTabela(object sender, PrintPageEventArgs e) { try { // Definição dos dados do cedente CedenteInfo Cedente = new CedenteInfo(); Cedente.Cedente = "outro cedente!"; Cedente.Banco = "237"; Cedente.Agencia = "1234-5"; Cedente.Conta = "123456-7"; Cedente.Carteira = "06"; Cedente.Modalidade = "11"; // Definição dos dados do sacado SacadoInfo Sacado = new SacadoInfo(); Sacado.Sacado = (string)tbDados.Rows[nReg]["Nome"]; // Definição das Variáveis do boleto BoletoInfo Boleto = new BoletoInfo(); Boleto.DataVencimento = (DateTime)tbDados.Rows[nReg]["Vencimento"]; Boleto.ValorDocumento = (double)tbDados.Rows[nReg]["Valor"]; Boleto.NossoNumero = tbDados.Rows[nReg]["NossoNumero"].ToString(); Boleto.NumeroDocumento = Boleto.NossoNumero; // Cria uma nova instancia totalmente idependente BoletoForm bol = new BoletoForm(); // monta o boleto com os dados específicos nas classes bol.MakeBoleto(Cedente, Sacado, Boleto); bol.PrintType = PrintTypes.Documet; bol.Print(e.Graphics); nReg++; e.HasMorePages = nReg < tbDados.Rows.Count; } catch (Exception) { } }
private void printHeader(PrintPageEventArgs ev, ref float yPos, int tab) { float leftMargin = 50; // Print watermark "Preliminär" if (printPrelResults) { ev.Graphics.RotateTransform(45); Font prelFont = new Font("Arial", 90, System.Drawing.FontStyle.Regular); ev.Graphics.DrawString("Preliminärresultat", prelFont, Brushes.LightGray, ev.MarginBounds.Left, 0, new StringFormat()); ev.Graphics.RotateTransform(-45); } // Print logo System.Drawing.Image image = getLogo(); ev.Graphics.DrawImage( image, ev.MarginBounds.Right - image.Width / 4, 20, image.Width / 4, image.Height / 4); // Print page header ev.Graphics.DrawString("Tävling: ", printHeaderFont, Brushes.Black, leftMargin, yPos, new StringFormat()); ev.Graphics.DrawString(CommonCode.GetCompetitions()[0].Name, printHeaderFont, Brushes.Black, leftMargin + tab, yPos, new StringFormat()); yPos += printHeaderFont.GetHeight(); ev.Graphics.DrawString("Vapengrupp: ", printHeaderFont, Brushes.Black, leftMargin, yPos, new StringFormat()); ev.Graphics.DrawString(wclass.ToString(), printHeaderFont, Brushes.Black, leftMargin + tab, yPos, new StringFormat()); yPos += printHeaderFont.GetHeight(); if (this.clubId != null) { Structs.Club club = CommonCode.GetClub(clubId); ev.Graphics.DrawString("Skytteklubb: ", printHeaderFont, Brushes.Black, leftMargin, yPos, new StringFormat()); ev.Graphics.DrawString(club.Name, printHeaderFont, Brushes.Black, leftMargin + tab, yPos, new StringFormat()); yPos += printHeaderFont.GetHeight(); } // // Print allberg on bottom ev.Graphics.DrawString("Utskriven " + DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString(), printAllbergFont, Brushes.Black, ev.PageBounds.Right - 250, ev.PageBounds.Size.Height - 2 * printHeaderFont.GetHeight() - 20, new StringFormat()); }
static void pDoc_PrintPage(object sender, PrintPageEventArgs e) { Graphics g = e.Graphics; Image imgLogo = (Image)Properties.Resources.PaperLogo; Font fntReg = new Font("Arial", 15, FontStyle.Regular); Font fntBold = new Font("Arial", 15, FontStyle.Bold); SolidBrush brSol = new SolidBrush(Color.Black); StringFormat fmtString = new StringFormat(); g.DrawImage(imgLogo, new RectangleF(0, 0, e.PageBounds.Width, imgLogo.Height - 80)); int y = (imgLogo.Height - 80) + 10; fmtString.Alignment = StringAlignment.Far; g.DrawString("Reg. no.: " + Jobs.REGISTRATION_NUMBER, fntReg, brSol, e.PageBounds.Width - 10, y, fmtString); g.DrawString("Loan no.: " + loanNumber, fntReg, brSol, 10, y); y += fntReg.Height + 20; if (custPhoto != null) { int pW = 240, pH = 180; int pX = e.PageBounds.Width - pW - 10, pY = y; g.DrawImage(custPhoto, new RectangleF(pX, pY, pW, pH)); } int maxWidth = e.PageBounds.Width - 240 - 20; int maxWidthInY = (y + 200); int x = 10; y += 10; RectangleF tmpRF = new RectangleF(x, y, maxWidthInY > y ? maxWidth : e.PageBounds.Width - 20, fntReg.Height * 2); g.DrawString("Customer Name : ", fntBold, brSol, x, y); y += fntBold.Height; tmpRF = new RectangleF(x, y, maxWidthInY > y ? maxWidth : e.PageBounds.Width - 20, fntReg.Height * 2); g.DrawString(custName, fntReg, brSol, tmpRF); y += (int)g.MeasureString(custName, fntReg, tmpRF.Size).Height; y += 10; g.DrawString("Contact Number : ", fntBold, brSol, x, y); y += fntBold.Height; tmpRF = new RectangleF(x, y, maxWidthInY > y ? maxWidth : e.PageBounds.Width - 20, fntReg.Height * 1); g.DrawString(custCNo, fntReg, brSol, tmpRF); y += (int)g.MeasureString(custCNo, fntReg, tmpRF.Size).Height; y += 10; g.DrawString("Customer Address : ", fntBold, brSol, x, y); y += fntBold.Height; tmpRF = new RectangleF(x, y, maxWidthInY > y ? maxWidth : e.PageBounds.Width - 20, fntReg.Height * 3); g.DrawString(custAddress, fntReg, brSol, tmpRF); y += (int)g.MeasureString(custAddress, fntReg, tmpRF.Size).Height; y += 10; g.DrawString("Refference Name : ", fntBold, brSol, x, y); y += fntBold.Height; tmpRF = new RectangleF(x, y, maxWidthInY > y ? maxWidth : e.PageBounds.Width - 20, fntReg.Height * 1); g.DrawString(refName, fntReg, brSol, tmpRF); y += (int)g.MeasureString(refName, fntReg, tmpRF.Size).Height; y += 10; g.DrawString("Refference Contact : ", fntBold, brSol, x, y); y += fntBold.Height; tmpRF = new RectangleF(x, y, maxWidthInY > y ? maxWidth : e.PageBounds.Width - 20, fntReg.Height * 1); g.DrawString(refCNo, fntReg, brSol, tmpRF); y += (int)g.MeasureString(refCNo, fntReg, tmpRF.Size).Height; y += 20; float col1 = (float)(e.PageBounds.Width * 0.20); float col2 = (float)(e.PageBounds.Width * 0.80); fntBold = new Font(fntBold, FontStyle.Underline); tmpRF = new RectangleF(x, y, col1, fntBold.Height); g.DrawString("Mortgage Item", fntBold, brSol, tmpRF); tmpRF = new RectangleF(col1, y, col2, fntBold.Height); g.DrawString("Remark", fntBold, brSol, tmpRF); y += fntBold.Height + 10; fntBold = new Font(fntReg, FontStyle.Bold); int itemCounter = 1, rmLines = 4; fntReg = new Font("Arial", 12, FontStyle.Regular); String curStr = ""; curStr = rmCheck; if (curStr.Trim().Length > 0) { tmpRF = new RectangleF(x, y, col1, fntReg.Height); g.DrawString(itemCounter + ". Check", fntReg, brSol, tmpRF); tmpRF = new RectangleF(col1, y, col2, fntReg.Height * rmLines); g.DrawString(curStr, fntReg, brSol, tmpRF); y += (((int)g.MeasureString(curStr, fntReg, tmpRF.Size).Height) + 10); itemCounter++; } curStr = rmVehicle; if (curStr.Trim().Length > 0) { tmpRF = new RectangleF(x, y, col1, fntReg.Height); g.DrawString(itemCounter + ". Vehicle", fntReg, brSol, tmpRF); tmpRF = new RectangleF(col1, y, col2, fntReg.Height * rmLines); g.DrawString(curStr, fntReg, brSol, tmpRF); y += (((int)g.MeasureString(curStr, fntReg, tmpRF.Size).Height) + 10); itemCounter++; } curStr = rmGold; if (curStr.Trim().Length > 0) { tmpRF = new RectangleF(x, y, col1, fntReg.Height); g.DrawString(itemCounter + ". Gold", fntReg, brSol, tmpRF); tmpRF = new RectangleF(col1, y, col2, fntReg.Height * rmLines); g.DrawString(curStr, fntReg, brSol, tmpRF); y += (((int)g.MeasureString(curStr, fntReg, tmpRF.Size).Height) + 10); itemCounter++; } curStr = rmDocument; if (curStr.Trim().Length > 0) { tmpRF = new RectangleF(x, y, col1, fntReg.Height); g.DrawString(itemCounter + ". Document", fntReg, brSol, tmpRF); tmpRF = new RectangleF(col1, y, col2, fntReg.Height * rmLines); g.DrawString(curStr, fntReg, brSol, tmpRF); y += (((int)g.MeasureString(curStr, fntReg, tmpRF.Size).Height) + 10); itemCounter++; } fntReg = new Font("Arial", 12, FontStyle.Regular); y = e.PageBounds.Height - (fntReg.Height * 4); g.DrawString("Signature", fntReg, brSol, x + 20, y); x = e.PageBounds.Width - 30; fmtString = new StringFormat(); fmtString.Alignment = StringAlignment.Far; g.DrawString("Proprietary Signature", fntReg, brSol, x, y, fmtString); }
private void printTeamResult(PrintPageEventArgs ev, ref float yPos, int place, ResultsReturnTeam result) { int nrOfLinesThisResult = 1; printString(ev, place.ToString(), printCompetitorFont, this.colTeamPlace, yPos, this.colTeamClub - this.colTeamPlace); printString(ev, CommonCode.GetClub(result.ClubId).Name, printCompetitorFont, this.colTeamClub, yPos, this.colTeamName - this.colTeamClub); printString(ev, result.TeamName, printCompetitorFont, this.colTeamName, yPos, this.colTeamResult - this.colTeamName); float xPosHitsPerStn = this.colTeamResult; foreach (string strnTemp in result.HitsPerStn.Split(';')) { string strn = strnTemp; if (xPosHitsPerStn + ev.Graphics.MeasureString(strn, printCompetitorFont).Width > colTeamResultMaxWidth) { nrOfLinesThisResult++; xPosHitsPerStn = this.colTeamResult; } if (strn != "") { switch (CompetitionType) { case Structs.CompetitionTypeEnum.Field: if (!competition.NorwegianCount) { string[] parts = strn.Split('/'); int hits = int.Parse(parts[0]); int figures = int.Parse(parts[1]); strn = hits.ToString(); } else { } break; case Structs.CompetitionTypeEnum.MagnumField: if (!competition.NorwegianCount) { string[] parts = strn.Split('/'); int hits = int.Parse(parts[0]); int figures = int.Parse(parts[1]); strn = hits.ToString(); } else { } break; case Structs.CompetitionTypeEnum.Precision: break; } } ev.Graphics.DrawString(strn, printCompetitorFont, Brushes.Black, xPosHitsPerStn, yPos + (nrOfLinesThisResult - 1) * printCompetitorHeaderFont.GetHeight(), new StringFormat()); xPosHitsPerStn += ev.Graphics.MeasureString(strn + " ", printCompetitorFont).Width; } switch (CompetitionType) { case Structs.CompetitionTypeEnum.Field: { if (competition.NorwegianCount) { printString(ev, (result.Hits + result.FigureHits).ToString(), printCompetitorFont, this.colTeamResultTot, yPos, this.colTeamPoints - this.colTeamResultTot); } else { printString(ev, result.Hits.ToString() + "/" + result.FigureHits.ToString(), printCompetitorFont, this.colTeamResultTot, yPos, this.colTeamPoints - this.colTeamResultTot); } printString(ev, result.Points.ToString(), printCompetitorFont, this.colTeamPoints, yPos, this.RightMargin - this.colTeamPoints); break; } case Structs.CompetitionTypeEnum.MagnumField: { printString(ev, result.Hits.ToString() + "/" + result.FigureHits.ToString(), printCompetitorFont, this.colTeamResultTot, yPos, this.colTeamPoints - this.colTeamResultTot); printString(ev, result.Points.ToString(), printCompetitorFont, this.colTeamPoints, yPos, this.RightMargin - this.colTeamPoints); break; } case Structs.CompetitionTypeEnum.Precision: { printString(ev, result.Hits.ToString(), printCompetitorFont, this.colTeamResultTot, yPos, this.colTeamPoints - this.colTeamResultTot); break; } default: throw new ApplicationException("Unknown CompetitionType"); } yPos += nrOfLinesThisResult * printCompetitorHeaderFont.GetHeight(); }
public void FacturaA(PrintPageEventArgs e, int idFact) { DataSet dsRemitoA = new DataSet(); DataSet dsFacturaA = new DataSet(); DataSet dsEmpresa = new DataSet(); DataSet dsCliente = new DataSet(); DataSet dsFacturaCliente = new DataSet(); String detalleFact; String idcliente; C.CargarDatos(dsFacturaA, "dsFacturaA", "select max(idfactura) from factura"); String idFact = ((dsFacturaA.Tables[0].Rows[0][0]).ToString()); dsFacturaA.Clear(); C.CargarDatos(dsFacturaA, "dsFacturaA", "select flete,seguro,total from factura where idfactura=" + idFact); C.CargarDatos(dsRemitoA, "dsRemitoA", "select * from remito where idfactura=" + idFact); Console.WriteLine("select * from remito where idfactura=" + idFact); detalleFact = Remito.getInfoRemito(C,dsRemitoA.Tables[0].Rows[0][0].ToString()); String fecha = DateTime.Now.ToShortDateString(); C.CargarDatos(dsEmpresa, "dsEmpresa", "select * from empresa"); String remitente = (dsEmpresa.Tables[0].Rows[0][1].ToString()); String dirRemitente = (dsEmpresa.Tables[0].Rows[0][2].ToString()); String telefonoEmpresa = (dsEmpresa.Tables[0].Rows[0][3].ToString()); String ciudadRemitente = (dsEmpresa.Tables[0].Rows[0][4].ToString()); String cuilRemitente = ""; C.CargarDatos(dsFacturaCliente, "dsFacturaCliente", "select idcliente from factura where idfactura=" + idFact); idcliente = dsFacturaCliente.Tables[0].Rows[0][0].ToString(); C.CargarDatos(dsCliente,"dsCliente","select nombre,apellido,direccion,CUIL,ciudad from clientes where idcliente=" + idcliente); String destinatario = (dsCliente.Tables[0].Rows[0][0].ToString()+ " "+dsCliente.Tables[0].Rows[0][1].ToString()); String dirDestinatario = (dsCliente.Tables[0].Rows[0][2].ToString()); String ciudadDestinatario = (dsCliente.Tables[0].Rows[0][4].ToString()); String cuilDestinatario = (dsCliente.Tables[0].Rows[0][3].ToString()); String IVA = (dsRemitoA.Tables[0].Rows[0][11].ToString()); String VD = (dsRemitoA.Tables[0].Rows[0][12].ToString()); String CR = (dsRemitoA.Tables[0].Rows[0][13].ToString()); String condVenta = (dsRemitoA.Tables[0].Rows[0][10].ToString()); DataSet aux = new DataSet(); C.CargarDatos(aux, "aux", "select flete,seguro,total,neto,ivari from factura where idfactura=" + idFact); String flete = (aux.Tables[0].Rows[0][0].ToString()); ; String seguro = (aux.Tables[0].Rows[0][1].ToString()); ; String total = (aux.Tables[0].Rows[0][2].ToString()); ; String neto = (aux.Tables[0].Rows[0][3].ToString()); String ivari = (aux.Tables[0].Rows[0][4].ToString()); Font font = new Font("Tahoma", 10, FontStyle.Bold); //Imprime la fecha actual //Fecha 1100 / 1170 / 1250 - 270 e.Graphics.DrawString(fecha, font, Brushes.Black, PrinterUnitConvert.Convert(1050, PrinterUnit.TenthsOfAMillimeter, PrinterUnit.Display), PrinterUnitConvert.Convert(200, PrinterUnit.TenthsOfAMillimeter, PrinterUnit.Display)); //Remitente 400 - 550 e.Graphics.DrawString(remitente, font, Brushes.Black, PrinterUnitConvert.Convert(390, PrinterUnit.TenthsOfAMillimeter, PrinterUnit.Display), PrinterUnitConvert.Convert(480, PrinterUnit.TenthsOfAMillimeter, PrinterUnit.Display)); //Destinatario 1200 - 550 e.Graphics.DrawString(destinatario, font, Brushes.Black, PrinterUnitConvert.Convert(1190, PrinterUnit.TenthsOfAMillimeter, PrinterUnit.Display), PrinterUnitConvert.Convert(480, PrinterUnit.TenthsOfAMillimeter, PrinterUnit.Display)); //Domicilio 380 - 610 e.Graphics.DrawString(dirRemitente, font, Brushes.Black, PrinterUnitConvert.Convert(370, PrinterUnit.TenthsOfAMillimeter, PrinterUnit.Display), PrinterUnitConvert.Convert(540, PrinterUnit.TenthsOfAMillimeter, PrinterUnit.Display)); //Domicilio 1160 - 610 e.Graphics.DrawString(dirDestinatario, font, Brushes.Black, PrinterUnitConvert.Convert(1140, PrinterUnit.TenthsOfAMillimeter, PrinterUnit.Display), PrinterUnitConvert.Convert(540, PrinterUnit.TenthsOfAMillimeter, PrinterUnit.Display)); //Localidad 400 - 670 e.Graphics.DrawString(ciudadRemitente, font, Brushes.Black, PrinterUnitConvert.Convert(390, PrinterUnit.TenthsOfAMillimeter, PrinterUnit.Display), PrinterUnitConvert.Convert(590, PrinterUnit.TenthsOfAMillimeter, PrinterUnit.Display)); //Localidad 1170 - 670 e.Graphics.DrawString(ciudadDestinatario, font, Brushes.Black, PrinterUnitConvert.Convert(1190, PrinterUnit.TenthsOfAMillimeter, PrinterUnit.Display), PrinterUnitConvert.Convert(590, PrinterUnit.TenthsOfAMillimeter, PrinterUnit.Display)); //C.U.I.T. 340 - 730 e.Graphics.DrawString(cuilRemitente, font, Brushes.Black, PrinterUnitConvert.Convert(340, PrinterUnit.TenthsOfAMillimeter, PrinterUnit.Display), PrinterUnitConvert.Convert(660, PrinterUnit.TenthsOfAMillimeter, PrinterUnit.Display)); //C.U.I.T. 1120 - 730 e.Graphics.DrawString(cuilDestinatario, font, Brushes.Black, PrinterUnitConvert.Convert(1110, PrinterUnit.TenthsOfAMillimeter, PrinterUnit.Display), PrinterUnitConvert.Convert(660, PrinterUnit.TenthsOfAMillimeter, PrinterUnit.Display)); //Cuenta Corriente 910 - 800 e.Graphics.DrawString("x", font, Brushes.Black, PrinterUnitConvert.Convert(820, PrinterUnit.TenthsOfAMillimeter, PrinterUnit.Display), PrinterUnitConvert.Convert(735, PrinterUnit.TenthsOfAMillimeter, PrinterUnit.Display)); //Flete //A cobrar 1180 - 1420 e.Graphics.DrawString(flete, font, Brushes.Black, PrinterUnitConvert.Convert(1160, PrinterUnit.TenthsOfAMillimeter, PrinterUnit.Display), PrinterUnitConvert.Convert(1350, PrinterUnit.TenthsOfAMillimeter, PrinterUnit.Display)); //seguro //A cobrar 1180 - 1480 e.Graphics.DrawString(seguro, font, Brushes.Black, PrinterUnitConvert.Convert(1160, PrinterUnit.TenthsOfAMillimeter, PrinterUnit.Display), PrinterUnitConvert.Convert(1410, PrinterUnit.TenthsOfAMillimeter, PrinterUnit.Display)); //total //A cobrar 1180 - 1720 e.Graphics.DrawString(total, font, Brushes.Black, PrinterUnitConvert.Convert(1160, PrinterUnit.TenthsOfAMillimeter, PrinterUnit.Display), PrinterUnitConvert.Convert(1670, PrinterUnit.TenthsOfAMillimeter, PrinterUnit.Display)); //Neto e.Graphics.DrawString(neto, font, Brushes.Black, PrinterUnitConvert.Convert(1150, PrinterUnit.TenthsOfAMillimeter, PrinterUnit.Display), PrinterUnitConvert.Convert(1480, PrinterUnit.TenthsOfAMillimeter, PrinterUnit.Display)); //IVA R.I. e.Graphics.DrawString(ivari, font, Brushes.Black, PrinterUnitConvert.Convert(1150, PrinterUnit.TenthsOfAMillimeter, PrinterUnit.Display), PrinterUnitConvert.Convert(1550, PrinterUnit.TenthsOfAMillimeter, PrinterUnit.Display)); List<String> detalleDividido = new List<String>(7); detalleFact=richTextDescripcion.Text.ToString(); detalleDividido=dividirDescripcion(detalleFact); e.Graphics.DrawString(detalleDividido.ElementAt(0), font, Brushes.Black, PrinterUnitConvert.Convert(320, PrinterUnit.TenthsOfAMillimeter, PrinterUnit.Display), PrinterUnitConvert.Convert(900, PrinterUnit.TenthsOfAMillimeter, PrinterUnit.Display)); e.Graphics.DrawString(detalleDividido.ElementAt(1), font, Brushes.Black, PrinterUnitConvert.Convert(320, PrinterUnit.TenthsOfAMillimeter, PrinterUnit.Display), PrinterUnitConvert.Convert(950, PrinterUnit.TenthsOfAMillimeter, PrinterUnit.Display)); e.Graphics.DrawString(detalleDividido.ElementAt(2), font, Brushes.Black, PrinterUnitConvert.Convert(320, PrinterUnit.TenthsOfAMillimeter, PrinterUnit.Display), PrinterUnitConvert.Convert(1000, PrinterUnit.TenthsOfAMillimeter, PrinterUnit.Display)); e.Graphics.DrawString(detalleDividido.ElementAt(3), font, Brushes.Black, PrinterUnitConvert.Convert(320, PrinterUnit.TenthsOfAMillimeter, PrinterUnit.Display), PrinterUnitConvert.Convert(1050, PrinterUnit.TenthsOfAMillimeter, PrinterUnit.Display)); e.Graphics.DrawString(detalleDividido.ElementAt(4), font, Brushes.Black, PrinterUnitConvert.Convert(320, PrinterUnit.TenthsOfAMillimeter, PrinterUnit.Display), PrinterUnitConvert.Convert(1100, PrinterUnit.TenthsOfAMillimeter, PrinterUnit.Display)); e.Graphics.DrawString(detalleDividido.ElementAt(5), font, Brushes.Black, PrinterUnitConvert.Convert(320, PrinterUnit.TenthsOfAMillimeter, PrinterUnit.Display), PrinterUnitConvert.Convert(1150, PrinterUnit.TenthsOfAMillimeter, PrinterUnit.Display)); e.Graphics.DrawString(detalleDividido.ElementAt(6), font, Brushes.Black, PrinterUnitConvert.Convert(320, PrinterUnit.TenthsOfAMillimeter, PrinterUnit.Display), PrinterUnitConvert.Convert(1200, PrinterUnit.TenthsOfAMillimeter, PrinterUnit.Display)); //Resp. Insc. 1220 - 800 e.Graphics.DrawString("x", font, Brushes.Black, PrinterUnitConvert.Convert(1160, PrinterUnit.TenthsOfAMillimeter, PrinterUnit.Display), PrinterUnitConvert.Convert(745, PrinterUnit.TenthsOfAMillimeter, PrinterUnit.Display)); }//end printFacturaA
// The function that print a bunch of rows that fit in one page // Returns true if there are more rows to print, so another PagePrint action is required // Returns false when all rows are printed (the _currentRow parameter reaches the last row of the DataGridView control) and no further PagePrint action is required private bool drawRows(PrintPageEventArgs e) { var rowsPrinted = 0; while (_currentRow < _dataGridView.Rows.Count -1) { if (rowsPrinted == 5) return true; if (_dataGridView.Rows[_currentRow].Visible) // Print the cells of the _currentRow only if that row is visible { var row = _dataGridView.Rows[_currentRow]; //draw ownername and holdername var owner = row.Cells["OwnerName"].Value ?? string.Empty; var holder = row.Cells["HolderName"].Value ?? string.Empty; drawRow(e.Graphics, owner.ToString(), holder.ToString()); //Draw Address and Prop ID var address = row.Cells["Address"].Value ?? string.Empty; var propertyID = row.Cells["PropertyID"].Value ?? string.Empty; drawRow(e.Graphics,address.ToString(), propertyID.ToString()); //Draw Addr2 and Prop Desc var address2 = row.Cells["Address2"].Value ?? string.Empty; var propertyDesc = row.Cells["PropertyDescription"].Value ?? string.Empty; drawRow(e.Graphics,address2.ToString(), propertyDesc.ToString()); //Draw Addr3 var address3 = row.Cells["Address3"].Value ?? string.Empty; drawRow(e.Graphics, address3.ToString()); //Draw City, State Zip var city = row.Cells["City"].Value ?? string.Empty; var state = row.Cells["State"].Value ?? string.Empty; var zip = row.Cells["Zip"].Value ?? string.Empty; var formatted = string.Format("{0}, {1} {2}",city,state,zip); drawRow(e.Graphics, formatted); // draw line e.Graphics.DrawLine(_linePen, _column1.X, _column1.Y, 750, _column1.Y); // add a touch to the Y axis _column1.Y += 6; _column2.Y += 6; // draw Date and Amount var date = Convert.ToDateTime(row.Cells["DateReceived"].Value); var dateFormatted = date.ToString("MM/dd/yyyy") ?? string.Empty; var amount = row.Cells["Value"].FormattedValue ?? string.Empty; formatted = string.Format("{0} {1}", dateFormatted, amount); drawRow(e.Graphics, formatted); // draw line e.Graphics.DrawLine(_linePen, _column1.X, _column1.Y, 750, _column1.Y); drawRow(e.Graphics); rowsPrinted += 1; } _currentRow ++; } return false; }
private void pdPrint_PrintPage(object sender, PrintPageEventArgs e) { float x, y, lineOffset; double toplam = 0; // Font seçimi Font printFont = new Font("Lucida Console", (float)7, FontStyle.Regular, GraphicsUnit.Point); // Substituted to FontA Font e.Graphics.PageUnit = GraphicsUnit.Point; // Resim çizdir x = 79; y = 0; int a = Convert.ToInt32(e.PageSettings.PrintableArea.Width - ("Toplam " + toplam + " TL").Length); // Fişi hazırla lineOffset = 7 + printFont.GetHeight(e.Graphics) - (float)3.5; x = 0; y = lineOffset; e.Graphics.DrawString(DateTime.Now.ToString("yyyy-MM-dd HH:mm"), printFont, Brushes.Black, Convert.ToInt32(80 - (DateTime.Now.ToString("yyyy-MM-dd HH:mm").ToString()).Length), y); y += lineOffset * 2; e.Graphics.DrawString(anaform.labelyetkili.Text, printFont, Brushes.Black, Convert.ToInt32(62 - ((anaform.labelyetkili.Text.Length * 11 / 2) / 4)), y); y += lineOffset; e.Graphics.DrawString(anaform.textBoxFirmaBaslik.Text, printFont, Brushes.Black, Convert.ToInt32(62 - ((anaform.textBoxFirmaBaslik.Text.Length * 11 / 2) / 4)), y); y += lineOffset; e.Graphics.DrawString(anaform.textBoxFisBaslik.Text, printFont, Brushes.Black, Convert.ToInt32(62 - ((anaform.textBoxFisBaslik.Text.Length * 11 / 2) / 4)), y); y += lineOffset; e.Graphics.DrawString("______________________________________", printFont, Brushes.Black, x, y); y += lineOffset; //if (anaform.radioButton1.Checked) { e.Graphics.DrawString("Müşteri : " + yazdirilacakOgrenci.KartNo + "-" + yazdirilacakOgrenci.Ad + " " + yazdirilacakOgrenci.Soyad, printFont, Brushes.Black, x, y); y += lineOffset; e.Graphics.DrawString("______________________________________", printFont, Brushes.Black, x, y); y += lineOffset; e.Graphics.DrawString("Ürün Listesi", printFont, Brushes.Black, (62 - (("Ürün Listesi".Length * 11 / 2) / 4)), y); y += lineOffset; } foreach (var item in yazdirilacaksepet) { e.Graphics.DrawString(item.Adet + " * " + item.urun.Ad, printFont, Brushes.Black, x, y); e.Graphics.DrawString((item.urun.Fiyat * item.Adet).ToString() + " TL", printFont, Brushes.Black, Convert.ToInt32(110 - ((item.urun.Fiyat * item.Adet).ToString() + " TL").Length), y); toplam += Convert.ToDouble(item.urun.Fiyat * item.Adet); y += lineOffset; } e.Graphics.DrawString("______________________________________", printFont, Brushes.Black, x, y); Font printFontBold = new Font("MingLiU", 10, FontStyle.Regular, GraphicsUnit.Point); lineOffset = printFontBold.GetHeight(e.Graphics) - 4; y += lineOffset; e.Graphics.DrawString("Toplam : " + toplam + " TL", printFontBold, Brushes.Black, Convert.ToInt32(82 - ("Toplam : " + toplam + " TL").Length), y); y += lineOffset * 2; e.Graphics.DrawString("Kalan Bakiye : " + yazdirilacakOgrenci.Bakiye + " TL", printFont, Brushes.Black, Convert.ToInt32(54 - ("Kalan Bakiye :" + yazdirilacakOgrenci.Bakiye + " TL").Length), y); y += lineOffset; e.Graphics.DrawString("______________________________________", printFont, Brushes.Black, x, y); y += lineOffset * 2; e.Graphics.DrawString("---" + anaform.textBoxsonSatir.Text + "---", printFontBold, Brushes.Black, Convert.ToInt32(62 - ((("---" + anaform.textBoxsonSatir.Text + "---").Length * 11 / 2) / 4)), y); y += lineOffset * 4; e.Graphics.DrawString("______________________________________", printFontBold, Brushes.Black, x, y); y += lineOffset * 4; e.HasMorePages = false; //yazdırma işlemi tamamlandı }
protected override void OnPrintPage(PrintPageEventArgs e) { base.OnPrintPage(e); int printHeight = DefaultPageSettings.PaperSize.Height - DefaultPageSettings.Margins.Top - DefaultPageSettings.Margins.Bottom; int printWidth = DefaultPageSettings.PaperSize.Width - DefaultPageSettings.Margins.Left - DefaultPageSettings.Margins.Right; int leftMargin = DefaultPageSettings.Margins.Left; int topMargin = DefaultPageSettings.Margins.Top; PointF cursor = new PointF(leftMargin, topMargin); //in essence where I am currently editing SizeF measuredSize; //Used to store the results from measurements of string size SizeF totalSize; //Used to store the size of the entire line, used to calculate spacing #region print dockside branding Bitmap branding = global::Prototype.Properties.Resources.docksideBranding; e.Graphics.DrawImage(branding, new RectangleF(leftMargin + (printWidth - 300) / 2, topMargin, 300, 100)); cursor.Y += 100; #endregion #region print customer title measuredSize = e.Graphics.MeasureString("Customer", fontTitle, printWidth); cursor.X = leftMargin; e.Graphics.DrawString("Customer", fontTitle, Brushes.Black, new Rectangle(Point.Round(cursor), Size.Round(measuredSize))); cursor.Y += measuredSize.Height; #endregion #region print customer name measuredSize = e.Graphics.MeasureString(name, fontName, printWidth); cursor.X = leftMargin; e.Graphics.DrawString(name, fontName, Brushes.Black, new RectangleF(cursor, measuredSize)); cursor.Y += measuredSize.Height; #endregion #region finding the largest field name totalSize = new SizeF(0, 0); foreach (string i in new string[] { "Customer ID", "Address", "Town", "County", "Landline", "Mobile" }) { measuredSize = e.Graphics.MeasureString(i, fontField); totalSize = DrawingTools.Max(totalSize, measuredSize); } #endregion #region printing all fields foreach (string[] field in new string[][] { new string[] { "Customer ID", customerID.ToString() }, new string[] { "Address", address }, new string[] { "Town", town }, new string[] { "County", county }, new string[] { "Landline", landline }, new string[] { "Mobile", mobile } }) { cursor.X = leftMargin; e.Graphics.DrawString(field[0], fontField, Brushes.Black, cursor); cursor.X += totalSize.Width; e.Graphics.DrawString(field[1], fontText, Brushes.Black, cursor); cursor.Y += totalSize.Height; } #endregion }
void pdoc_PrintPage(object sender, PrintPageEventArgs e) { Graphics graphics = e.Graphics; Font font = new Font("Verdana", 8); Font fontBold = new Font("Verdana", 8, FontStyle.Bold); Pen boldPen = new Pen(Color.Black, 3); Pen lightPen = new Pen(Color.Black, 1); float fontHeight = font.GetHeight(); int startX = 3; int startY = 2; int Offset = 5; graphics.DrawString(Description, new Font("Courier New", 13, FontStyle.Bold), new SolidBrush(Color.Black), startX, startY + Offset); Offset = Offset + 20; graphics.DrawString("Authorised money changer", font, new SolidBrush(Color.Black), startX, startY + Offset); graphics.DrawString(DateTime.Now.ToShortDateString(), font, new SolidBrush(Color.Black), startX + 180, startY + Offset); Offset = Offset + 18; graphics.DrawString(Address1, font, new SolidBrush(Color.Black), startX, startY + Offset); Offset = Offset + 18; graphics.DrawString(Address2, font, new SolidBrush(Color.Black), startX, startY + Offset); Offset = Offset + 18; graphics.DrawString(Address3 + " - " + PostalCode, font, new SolidBrush(Color.Black), startX, startY + Offset); Offset = Offset + 18; graphics.DrawString(string.Format("Phone: {0} LIC No : {1}", Phone, TaxRef), fontBold, new SolidBrush(Color.Black), startX, startY + Offset); Offset = Offset + 18; graphics.DrawString(string.Format("Receipt NO.:{0} Cash Customer", TranNo), fontBold, new SolidBrush(Color.Black), startX, startY + Offset); Offset = Offset + 18; string TranFullName = (TranType == "B") ? "Buy" : "Sell"; RectangleF rf = new RectangleF(startX, startY + Offset, 68, 30); graphics.DrawRectangle(lightPen, rf.X, rf.Y, rf.Width, rf.Height); StringFormat stringFormat = new StringFormat(); stringFormat.Alignment = StringAlignment.Center; stringFormat.LineAlignment = StringAlignment.Center; graphics.DrawString(CurCode, new Font("Verdana", 12, FontStyle.Bold), Brushes.Blue, rf, stringFormat); RectangleF rf1 = new RectangleF(startX + 68, startY + Offset, 66, 30); graphics.DrawRectangle(lightPen, rf1.X, rf1.Y, rf1.Width, rf1.Height); StringFormat stringFormat1 = new StringFormat(); stringFormat1.Alignment = StringAlignment.Center; stringFormat1.LineAlignment = StringAlignment.Center; graphics.DrawString(TranFullName, new Font("Verdana", 12, FontStyle.Bold), Brushes.Blue, rf1, stringFormat1); Offset = Offset + 10 + 30; RectangleF rf2 = new RectangleF(startX, startY + Offset, 135, 30); graphics.DrawRectangle(lightPen, rf2.X, rf2.Y, rf2.Width, rf2.Height); StringFormat stringFormat2 = new StringFormat(); stringFormat2.Alignment = StringAlignment.Far; stringFormat2.LineAlignment = StringAlignment.Center; graphics.DrawString("FC Amt", new Font("Verdana", 12, FontStyle.Bold), Brushes.Blue, rf2, stringFormat2); RectangleF rf3 = new RectangleF(startX + 135, startY + Offset, 146, 30); graphics.DrawRectangle(lightPen, rf3.X, rf3.Y, rf3.Width, rf3.Height); StringFormat stringFormat3 = new StringFormat(); stringFormat3.Alignment = StringAlignment.Far; stringFormat3.LineAlignment = StringAlignment.Center; graphics.DrawString("Local Amt", new Font("Verdana", 12, FontStyle.Bold), Brushes.Blue, rf3, stringFormat3); Offset = Offset + 30; RectangleF rf4 = new RectangleF(startX, startY + Offset, 135, 30); graphics.DrawRectangle(lightPen, rf4.X, rf4.Y, rf4.Width, rf4.Height); StringFormat stringFormat4 = new StringFormat(); stringFormat4.Alignment = StringAlignment.Far; stringFormat4.LineAlignment = StringAlignment.Center; graphics.DrawString(ForeignAmt, new Font("Verdana", 12, FontStyle.Bold), Brushes.Blue, rf4, stringFormat4); RectangleF rf5 = new RectangleF(startX + 135, startY + Offset, 146, 30); graphics.DrawRectangle(lightPen, rf5.X, rf5.Y, rf5.Width, rf5.Height); StringFormat stringFormat5 = new StringFormat(); stringFormat5.Alignment = StringAlignment.Far; stringFormat5.LineAlignment = StringAlignment.Center; graphics.DrawString(LocalAmt, new Font("Verdana", 12, FontStyle.Bold), Brushes.Blue, rf5, stringFormat5); string txt = ""; if (TranType == "B") { txt = "Please Pay: " + LocalAmt; } else { txt = "Please Collect: " + ForeignAmt; } Offset = Offset + 35; graphics.DrawString(txt, fontBold, new SolidBrush(Color.Black), startX, startY + Offset); Offset = Offset + 18; graphics.DrawString("Pls. Count $ check notes before leaving ", font, new SolidBrush(Color.Black), startX, startY + Offset); Offset = Offset + 18; graphics.DrawString("the counter as we shall not entertain", font, new SolidBrush(Color.Black), startX, startY + Offset); Offset = Offset + 18; graphics.DrawString("any complaints thereafter. Thank you.", font, new SolidBrush(Color.Black), startX, startY + Offset); }
public void Print(PrintPageEventArgs e, Rectangle rectangle, Graphics grap) { }
private void printDocument1_PrintPage(object sender, PrintPageEventArgs e) { try { int num = e.MarginBounds.Left; int num2 = e.MarginBounds.Top; bool flag = false; bool flag2 = this.bFirstPage; if (flag2) { foreach (DataGridViewColumn dataGridViewColumn in this.grdDuLieu.Columns) { int num3 = (int)Math.Floor((double)dataGridViewColumn.Width / (double)this.iTotalWidth * (double)this.iTotalWidth * ((double)e.MarginBounds.Width / (double)this.iTotalWidth)); this.iHeaderHeight = (int)e.Graphics.MeasureString(dataGridViewColumn.HeaderText, dataGridViewColumn.InheritedStyle.Font, num3).Height + 11; this.arrColumnLefts.Add(num); this.arrColumnWidths.Add(num3); num += num3; } e.Graphics.DrawString(this.mTieuDeBaoCao, new Font(System.Drawing.FontFamily.GenericSansSerif, 18f, FontStyle.Bold), Brushes.Black, (float)(e.MarginBounds.Left + 20), (float)e.MarginBounds.Top - e.Graphics.MeasureString(this.mTieuDeBaoCao, new Font(System.Drawing.FontFamily.GenericSansSerif, 18f, FontStyle.Bold), e.MarginBounds.Width).Height - 13f); } while (this.iRow <= this.grdDuLieu.Rows.Count - 1) { DataGridViewRow dataGridViewRow = this.grdDuLieu.Rows[this.iRow]; this.iCellHeight = dataGridViewRow.Height + 5; int num4 = 0; bool flag3 = num2 + this.iCellHeight >= e.MarginBounds.Height + e.MarginBounds.Top; if (flag3) { this.bNewPage = true; this.bFirstPage = false; flag = true; break; } bool flag4 = this.bNewPage; if (flag4) { num2 = e.MarginBounds.Top; foreach (DataGridViewColumn dataGridViewColumn2 in this.grdDuLieu.Columns) { e.Graphics.FillRectangle(new SolidBrush(Color.LightGray), new Rectangle((int)this.arrColumnLefts[num4], num2, (int)this.arrColumnWidths[num4], this.iHeaderHeight)); e.Graphics.DrawRectangle(Pens.Black, new Rectangle((int)this.arrColumnLefts[num4], num2, (int)this.arrColumnWidths[num4], this.iHeaderHeight)); e.Graphics.DrawString(dataGridViewColumn2.HeaderText, dataGridViewColumn2.InheritedStyle.Font, new SolidBrush(dataGridViewColumn2.InheritedStyle.ForeColor), new RectangleF((float)((int)this.arrColumnLefts[num4]), (float)num2, (float)((int)this.arrColumnWidths[num4]), (float)this.iHeaderHeight), this.strFormat); num4++; } this.bNewPage = false; num2 += this.iHeaderHeight; } num4 = 0; foreach (DataGridViewCell dataGridViewCell in dataGridViewRow.Cells) { bool flag5 = dataGridViewCell.Value != null; if (flag5) { decimal num5; bool flag6 = decimal.TryParse(dataGridViewCell.Value.ToString(), out num5); if (flag6) { e.Graphics.DrawString(num5.ToString("### ### ### ### ###"), dataGridViewCell.InheritedStyle.Font, new SolidBrush(dataGridViewCell.InheritedStyle.ForeColor), new RectangleF((float)((int)this.arrColumnLefts[num4]), (float)num2, (float)((int)this.arrColumnWidths[num4]), (float)this.iCellHeight), this.strFormat); } else { e.Graphics.DrawString(dataGridViewCell.Value.ToString(), dataGridViewCell.InheritedStyle.Font, new SolidBrush(dataGridViewCell.InheritedStyle.ForeColor), new RectangleF((float)((int)this.arrColumnLefts[num4]), (float)num2, (float)((int)this.arrColumnWidths[num4]), (float)this.iCellHeight), this.strFormat); } } e.Graphics.DrawRectangle(Pens.Black, new Rectangle((int)this.arrColumnLefts[num4], num2, (int)this.arrColumnWidths[num4], this.iCellHeight)); num4++; } this.iRow++; num2 += this.iCellHeight; } bool flag7 = flag; if (flag7) { e.HasMorePages = true; } else { e.HasMorePages = false; } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand); } }
private void _PrintDocument_PrintPage(object sender, PrintPageEventArgs e) { Graphics gs = e.Graphics; if (this.gs != null) { gs = this.gs; } else { #region 绘制磅单 int paddingleft = 90; //矩形距离左边的距离 int paddingtop = 80; //矩形距离上部的距离 int RowWeight = 700; //列表宽 int Height = LineHeight * (_BuyFuelTransport.Count + 1); //矩形的高 int top = 0; Rectangle r = new Rectangle(paddingleft, paddingtop, RowWeight, Height); //矩形的位置和大小 Pen pen = new Pen(Color.Black, 1); //画笔 gs.DrawRectangle(pen, r); float cloum1 = 40; //序号的宽 float cloum2 = 230; //供应商的宽 float cloum3 = 55; //煤种的宽 float cloum4 = 80; //车号的宽 float cloum5 = 70; //重量的宽 gs.DrawString("新乡中益发电有限公司入厂煤计量明细表(汽运)", new Font("宋体", 20, FontStyle.Bold, GraphicsUnit.Pixel), Brushes.Black, paddingleft + 130, 30); gs.DrawString("起始时间:" + StartTime.ToString("yyyy-MM-dd 03:00:00") + " 终止时间:" + EndTime.AddDays(1).ToString("yyyy-MM-dd 03:00:00") + " 单位:t", ContentFont, Brushes.Black, paddingleft + 10, 65); int seralinumber = 1;//序号 //列标题 //序号 string seralinumberTitle = "序号"; SizeF seralinumberSizeTitle = gs.MeasureString(seralinumberTitle, ContentFont); gs.DrawString(seralinumberTitle.ToString(), ContentFont, Brushes.Black, paddingleft + (cloum1 - seralinumberSizeTitle.Width) / 2, paddingtop + (LineHeight - seralinumberSizeTitle.Height) / 2); //供应商 string SupplierNameTitle = "供货单位"; SizeF SupplierNameSizeTitle = gs.MeasureString(SupplierNameTitle, ContentFont); gs.DrawString(SupplierNameTitle, ContentFont, Brushes.Black, paddingleft + cloum1 + (cloum2 - SupplierNameSizeTitle.Width) / 2, paddingtop + (LineHeight - SupplierNameSizeTitle.Height) / 2); //煤种 string KindNameTitle = "煤种"; SizeF KindNameSizeTitle = gs.MeasureString(KindNameTitle, ContentFont); gs.DrawString(KindNameTitle, ContentFont, Brushes.Black, paddingleft + cloum1 + cloum2 + (cloum3 - KindNameSizeTitle.Width) / 2, paddingtop + (LineHeight - KindNameSizeTitle.Height) / 2); //车牌号 string CarNumberTitle = "车牌号"; SizeF CarNumberSizeTitle = gs.MeasureString(CarNumberTitle, ContentFont); gs.DrawString(CarNumberTitle, ContentFont, Brushes.Black, paddingleft + cloum1 + cloum2 + cloum3 + (cloum4 - CarNumberSizeTitle.Width) / 2, paddingtop + (LineHeight - CarNumberSizeTitle.Height) / 2); //矿发量 string TicketWeightTitle = "矿发量"; SizeF TicketWeightSizeTitle = gs.MeasureString(TicketWeightTitle, ContentFont); gs.DrawString(TicketWeightTitle, ContentFont, Brushes.Black, paddingleft + cloum1 + cloum2 + cloum3 + cloum4 + (cloum5 - TicketWeightSizeTitle.Width) / 2, paddingtop + (LineHeight - TicketWeightSizeTitle.Height) / 2); //验收量 string CheckWeightTitle = "验收量"; SizeF CheckWeightSizeTitle = gs.MeasureString(CheckWeightTitle, ContentFont); gs.DrawString(CheckWeightTitle, ContentFont, Brushes.Black, paddingleft + cloum1 + cloum2 + cloum3 + cloum4 + cloum5 * 2 + (cloum5 - CheckWeightSizeTitle.Width) / 2, paddingtop + (LineHeight - CheckWeightSizeTitle.Height) / 2); foreach (CmcsBuyFuelTransport item in _BuyFuelTransport) { top = LineHeight * seralinumber; //序号 SizeF seralinumberSize = gs.MeasureString(seralinumber.ToString(), ContentFont); gs.DrawString(seralinumber.ToString(), ContentFont, Brushes.Black, paddingleft + (cloum1 - seralinumberSize.Width) / 2, paddingtop + top + (LineHeight - seralinumberSize.Height) / 2); //供应商 string SupplierName = item.SupplierName; SizeF SupplierNameSize = gs.MeasureString(SupplierName, ContentFont); if (item.Id == "合计") { gs.DrawString(SupplierName, ContentFont, Brushes.Black, paddingleft + (cloum1 + cloum2 + cloum3 + cloum4 - SupplierNameSize.Width) / 2, paddingtop + top + (LineHeight - SupplierNameSize.Height) / 2); } else { gs.DrawString(SupplierName, ContentFont, Brushes.Black, paddingleft + cloum1 + (cloum2 - SupplierNameSize.Width) / 2, paddingtop + top + (LineHeight - SupplierNameSize.Height) / 2); } //煤种 string KindName = item.FuelKindName; SizeF KindNameSize = gs.MeasureString(KindName, ContentFont); gs.DrawString(KindName, ContentFont, Brushes.Black, paddingleft + cloum1 + cloum2 + (cloum3 - KindNameSize.Width) / 2, paddingtop + top + (LineHeight - KindNameSize.Height) / 2); //车牌号 string CarNumber = item.CarNumber; SizeF CarNumberSize = gs.MeasureString(CarNumber, ContentFont); gs.DrawString(CarNumber, ContentFont, Brushes.Black, paddingleft + cloum1 + cloum2 + cloum3 + (cloum4 - CarNumberSize.Width) / 2, paddingtop + top + (LineHeight - CarNumberSize.Height) / 2); //矿发量 string TicketWeight = item.TicketWeight.ToString("F2"); SizeF TicketWeightSize = gs.MeasureString(TicketWeight, ContentFont); gs.DrawString(TicketWeight, ContentFont, Brushes.Black, paddingleft + cloum1 + cloum2 + cloum3 + cloum4 + (cloum5 - TicketWeightSize.Width) / 2, paddingtop + top + (LineHeight - TicketWeightSize.Height) / 2); //验收量 string CheckWeight = item.CheckWeight.ToString("F2"); SizeF CheckWeightSize = gs.MeasureString(CheckWeight, ContentFont); gs.DrawString(CheckWeight, ContentFont, Brushes.Black, paddingleft + cloum1 + cloum2 + cloum3 + cloum4 + cloum5 * 2 + (cloum5 - CheckWeightSize.Width) / 2, paddingtop + top + (LineHeight - CheckWeightSize.Height) / 2); gs.DrawLine(pen, paddingleft, paddingtop + LineHeight * seralinumber, paddingleft + RowWeight, paddingtop + LineHeight * seralinumber); seralinumber++; } gs.DrawString("计量站:", ContentFont, Brushes.Black, paddingleft, paddingtop + Height + 10); gs.DrawString("审核人:", ContentFont, Brushes.Black, paddingleft + 200, paddingtop + Height + 10); gs.DrawString("打印日期:" + DateTime.Now.ToString("yyyy年MM月dd日"), ContentFont, Brushes.Black, paddingleft + 400, paddingtop + Height + 10); gs.DrawLine(pen, paddingleft + cloum1, paddingtop, paddingleft + cloum1, paddingtop + Height); gs.DrawLine(pen, paddingleft + cloum1 + cloum2, paddingtop, paddingleft + cloum1 + cloum2, paddingtop + Height - LineHeight); gs.DrawLine(pen, paddingleft + cloum1 + cloum2 + cloum3, paddingtop, paddingleft + cloum1 + cloum2 + cloum3, paddingtop + Height - LineHeight); gs.DrawLine(pen, paddingleft + cloum1 + cloum2 + cloum3 + cloum4, paddingtop, paddingleft + cloum1 + cloum2 + cloum3 + cloum4, paddingtop + Height); gs.DrawLine(pen, paddingleft + cloum1 + cloum2 + cloum3 + cloum4 + cloum5, paddingtop, paddingleft + cloum1 + cloum2 + cloum3 + cloum4 + cloum5, paddingtop + Height); #endregion } }
protected override void doc_PrintPage(object sender, PrintPageEventArgs e) { //如果允许分页,则打印每一页,否则则打印当前页 if (_baseDoc.PagerSetting.AllowPage && _baseDoc.PagerSetting.PagerDesc.Count > 0) { _baseDoc.PageIndexChanged(_baseDoc.PagerSetting.PagerDesc[_pageIndex].PageIndex, _baseDoc.PagerSetting.PagerDesc[_pageIndex].IsMain, _baseDoc.DataSource); } //创建 metafile _printMetafile = GetPageMetafile(); //调整边距 Rectangle rect = new Rectangle(0, 0, _printMetafile.Width, _printMetafile.Height); double widthZoom = 1; double heightZoom = 1; double widthSize = (e.MarginBounds.Width); double heightSize = (e.MarginBounds.Height); if (widthSize < rect.Width) { widthZoom = widthSize / rect.Width; } //纵轴缩小 if (heightSize < rect.Height) { heightZoom = heightSize / rect.Height; } double zoom = (widthZoom < heightZoom) ? widthZoom : heightZoom; Rectangle zoomRect = new Rectangle(rect.X, rect.Y, (int)(rect.Width * zoom), (int)(rect.Height * zoom)); MemoryStream mStream = new MemoryStream(); Graphics ggggg = _baseDoc.CreateGraphics(); IntPtr ipHdctemp = ggggg.GetHdc(); Metafile mf = new Metafile(mStream, ipHdctemp); ggggg.ReleaseHdc(ipHdctemp); ggggg.Dispose(); Graphics gMf = Graphics.FromImage(mf); gMf.DrawImage(_printMetafile, zoomRect); gMf.Save(); gMf.Dispose(); _printMetafile = mf; metafileDelegate = new Graphics.EnumerateMetafileProc(MetafileCallback); //开始正式打印 PrintPage(_printMetafile, e, zoomRect.Width, zoomRect.Height); metafileDelegate = null; _pageIndex++; if (_pageFromHeight) { Rectangle r = GetPrintRect(); if ((_pageIndex) * _pagePrintHeight < r.Height) { e.HasMorePages = true; } } }
void document_PrintPage(object sender, PrintPageEventArgs e) { Font sFont = new Font("Arial", 12); Brush sBrush = Brushes.Black; //print current page e.Graphics.DrawString(letterEnumerator.Current.Item2, sFont, sBrush, e.MarginBounds, StringFormat.GenericTypographic); // advance enumerator to determine if we have more pages. e.HasMorePages = letterEnumerator.MoveNext(); }
private void Pd_PrintPage(object sender, PrintPageEventArgs e) { e.Graphics.DrawImage(_ImageTotal, 0, 0, new Rectangle(0, 0, _ImageTotal.Width, _ImageTotal.Height), GraphicsUnit.Pixel); }
// Render the contents of the RichTextBox for printing // Return the last character printed + 1 (printing start from this point for next page) public int Print(int charFrom, int charTo, PrintPageEventArgs e) { try { // Mark starting and ending character CHARRANGE cRange; cRange.cpMin = charFrom; cRange.cpMax = charTo; // Calculate the area to render and print RECT rectToPrint; rectToPrint.Top = (int)(e.MarginBounds.Top * AnInch); rectToPrint.Bottom = (int)(e.MarginBounds.Bottom * AnInch); rectToPrint.Left = (int)(e.MarginBounds.Left * AnInch); rectToPrint.Right = (int)(e.MarginBounds.Right * AnInch); // Calculate the size of the page RECT rectPage; rectPage.Top = (int)(e.PageBounds.Top * AnInch); rectPage.Bottom = (int)(e.PageBounds.Bottom * AnInch); rectPage.Left = (int)(e.PageBounds.Left * AnInch); rectPage.Right = (int)(e.PageBounds.Right * AnInch); IntPtr hdc = e.Graphics.GetHdc(); FORMATRANGE fmtRange; fmtRange.chrg = cRange; // Indicate character from to character to fmtRange.hdc = hdc; // Use the same DC for measuring and rendering fmtRange.hdcTarget = hdc; // Point at printer hDC fmtRange.rc = rectToPrint; // Indicate the area on page to print fmtRange.rcPage = rectPage; // Indicate whole size of page IntPtr res = IntPtr.Zero; IntPtr wparam = IntPtr.Zero; wparam = new IntPtr(1); // Move the pointer to the FORMATRANGE structure in memory IntPtr lparam = IntPtr.Zero; lparam = Marshal.AllocCoTaskMem(Marshal.SizeOf(fmtRange)); Marshal.StructureToPtr(fmtRange, lparam, false); // Send the rendered data for printing res = SendMessage(Handle, EM_FORMATRANGE, wparam, lparam); // Free the block of memory allocated Marshal.FreeCoTaskMem(lparam); // Release the device context handle obtained by a previous call e.Graphics.ReleaseHdc(hdc); // Return last + 1 character printer return res.ToInt32(); } catch (Exception) { return -1; } }
void printDoc_PrintPage(object sender, PrintPageEventArgs e) { int x = e.MarginBounds.Left; int y = e.MarginBounds.Top; Pen myPen = new Pen(Color.Gray); Brush brush = Brushes.LightGray; //////////////////////////打印表头/////////////////////////////////// if (printedRowsCount == 0) { if (mainTitle != "") { Font mainTitleFont = new Font(new FontFamily("宋体"), 20, FontStyle.Bold); SizeF strSize = e.Graphics.MeasureString(mainTitle, mainTitleFont, int.MaxValue); if (e.PageBounds.Width > strSize.Width) { x = (e.PageBounds.Width - Convert.ToInt32(strSize.Width)) / 2; } e.Graphics.DrawString(mainTitle, mainTitleFont, Brushes.Black, x, y); y += Convert.ToInt32(strSize.Height) + 5; x = e.MarginBounds.Left; } if (subTitle != "") { Font subTitleFont = new Font(new FontFamily("宋体"), 12, FontStyle.Bold); SizeF strSize = e.Graphics.MeasureString(subTitle, subTitleFont, int.MaxValue); if (e.PageBounds.Width > strSize.Width + 80) { x = (e.PageBounds.Width - Convert.ToInt32(strSize.Width)) * 2 / 3; } e.Graphics.DrawString(subTitle, subTitleFont, Brushes.Black, x, y); y += Convert.ToInt32(strSize.Height) + 5; x = e.MarginBounds.Left; } } ////////////////////////////////////////////////////////////////////// //////////////////////////打印列标题//////////////////////////////////////// for (int i = 0; i < sourceDGV.Columns.Count; i++) { int columnWidth = sourceDGV.Columns[i].Width; int headerHeight = sourceDGV.ColumnHeadersHeight; Rectangle rect = new Rectangle(x, y, columnWidth, headerHeight); e.Graphics.FillRectangle(brush, rect); e.Graphics.DrawRectangle(myPen, rect); DrawStringCenter(e.Graphics, sourceDGV.Columns[i].HeaderText, rect); x += rect.Width; } x = e.MarginBounds.Left; y += sourceDGV.ColumnHeadersHeight; ////////////////////////////////////////////////////////////////////////////// ///////////////////////////打印表格内容////////////////////////////////////// for (int i = printedRowsCount; i < sourceDGV.Rows.Count; i++) { int rowHeight = sourceDGV.Rows[i].Height; for (int j = 0; j < sourceDGV.Columns.Count; j++) { int columnWidth = sourceDGV.Columns[j].Width; Rectangle rect = new Rectangle(x, y, columnWidth, rowHeight); e.Graphics.DrawRectangle(myPen, rect); if (sourceDGV.Rows[i].Cells[j].Value != null) { DrawStringCenter(e.Graphics, sourceDGV.Rows[i].Cells[j].Value.ToString(), rect); } x += columnWidth; } printedRowsCount++; x = e.MarginBounds.Left; y += rowHeight; if (y > e.PageBounds.Height - 80 && printedRowsCount < sourceDGV.Rows.Count) { e.HasMorePages = true;//允许多页打印 return; } } printedRowsCount = 0; }
public virtual void OnEndPage(PrintDocument document, PrintPageEventArgs e) {}
private void Doc_PrintPage(object sender, PrintPageEventArgs e) { float x = e.MarginBounds.Left; float y = e.MarginBounds.Top; this.pbLabel.Width = 100; this.pbLabel.Height = 100; Bitmap bmp = new Bitmap(this.pbLabel.Width, this.pbLabel.Height); this.pbLabel.DrawToBitmap(bmp, new Rectangle(0, 0, this.pbLabel.Width, this.pbLabel.Height)); // e.Graphics.DrawImage((Image)bmp, x, y); e.Graphics.DrawImage((Image)bmp, 30, 40); string intlotcode = get_intlotcode(); String asfis = ""; String suppliercode = txtsuppcode.Text.Trim(); List <object[]> data = new List <object[]>(); MainMenu frm = new MainMenu(); data = frm.get_data_table_string("tbspecies", "", ""); if (data.Count > 0) { asfis = data[0][1].ToString(); } String origin = "INDONESIA"; String fishing_ground = get_fishing_ground(); String certcode = ""; String loincode = loin_code_global; String grade = cbgrade.Text.Trim(); double rweight = Double.Parse(txtweight.Text); String remark = txtremark.Text.Trim() + sign_remark(intlotcode, txtremark.Text.Trim()); String cert = cbcertificate.Text.Trim(); DateTime cutdate = dateTimePicker1.Value; String cutdatestr = cutdate.ToString("yy-MM-dd"); String productname = ""; data = frm.get_data_table_string("tbretouching", "intlotcode", intlotcode); if (data.Count > 0) { productname = data[0][2].ToString(); } data = frm.get_data_table_string("tbsupplier", "suppcode", suppliercode); if (data.Count > 0) { certcode = data[0][13].ToString(); } e.Graphics.DrawString(loincode, new Font("Arial", 8, FontStyle.Bold), Brushes.Black, 38, 145); String textfrozen = "Keep Frozen -18\u00b0C"; e.Graphics.DrawString(textfrozen, new Font("Arial", 8, FontStyle.Bold), Brushes.Black, 150, 160); e.Graphics.DrawString(grade, new Font("Arial", 20, FontStyle.Bold), Brushes.Black, 34, 15); String datalabel; datalabel = "Species"; e.Graphics.DrawString(datalabel, new Font("Arial", 8, FontStyle.Bold), Brushes.Black, 150, 20); datalabel = asfis; e.Graphics.DrawString(datalabel, new Font("Arial", 14, FontStyle.Bold), Brushes.Black, 150, 35); datalabel = "Grade"; e.Graphics.DrawString(datalabel, new Font("Arial", 8, FontStyle.Bold), Brushes.Black, 215, 20); datalabel = grade; e.Graphics.DrawString(datalabel, new Font("Arial", 14, FontStyle.Bold), Brushes.Black, 215, 35); datalabel = "Weight (Kg)"; e.Graphics.DrawString(datalabel, new Font("Arial", 8, FontStyle.Bold), Brushes.Black, 297, 20); datalabel = rweight.ToString(); e.Graphics.DrawString(datalabel, new Font("Arial", 14, FontStyle.Bold), Brushes.Black, 297, 35); //e.Graphics.DrawString(datalabel, new Font("Arial", 8, FontStyle.Bold), Brushes.Black, 140, 60); datalabel = "Internal Lot Code"; e.Graphics.DrawString(datalabel, new Font("Arial", 8, FontStyle.Bold), Brushes.Black, 148, 60); datalabel = intlotcode; e.Graphics.DrawString(datalabel, new Font("Arial", 13, FontStyle.Bold), Brushes.Black, 145, 75); datalabel = "Remark"; e.Graphics.DrawString(datalabel, new Font("Arial", 8, FontStyle.Bold), Brushes.Black, 316, 60); datalabel = remark; e.Graphics.DrawString(datalabel, new Font("Arial", 13, FontStyle.Bold), Brushes.Black, 315, 75); datalabel = "Origin"; e.Graphics.DrawString(datalabel, new Font("Arial", 8, FontStyle.Bold), Brushes.Black, 150, 100); datalabel = origin; e.Graphics.DrawString(datalabel, new Font("Arial", 8, FontStyle.Bold), Brushes.Black, 150, 115); datalabel = "Fishing Ground"; e.Graphics.DrawString(datalabel, new Font("Arial", 8, FontStyle.Bold), Brushes.Black, 215, 100); datalabel = fishing_ground; e.Graphics.DrawString(datalabel, new Font("Arial", 8, FontStyle.Bold), Brushes.Black, 220, 115); datalabel = "Processing Date: " + cutdatestr; e.Graphics.DrawString(datalabel, new Font("Arial", 8, FontStyle.Bold), Brushes.Black, 150, 130); if (!cert.Equals("") && !certcode.Equals("")) { datalabel = cert + " Code: " + certcode; e.Graphics.DrawString(datalabel, new Font("Arial", 8, FontStyle.Bold), Brushes.Black, 150, 145); } e.Graphics.DrawString(cert, new Font("Arial", 20, FontStyle.Bold), Brushes.Black, 60, 160); e.Graphics.DrawString(productname, new Font("Arial", 8, FontStyle.Bold), Brushes.Black, 150, 175); /* * * e.Graphics.DrawString(loincode, new Font("Arial", 8, FontStyle.Bold), Brushes.Black, 38, 145); * * e.Graphics.DrawString(grade, new Font("Arial", 20, FontStyle.Bold), Brushes.Black, 50, 15); * * String datalabel; * datalabel = "Species"; * e.Graphics.DrawString(datalabel, new Font("Arial", 8, FontStyle.Bold), Brushes.Black, 180, 20); * datalabel = asfis; * e.Graphics.DrawString(datalabel, new Font("Arial", 8, FontStyle.Bold), Brushes.Black, 180, 35); * * datalabel = "Grade"; * e.Graphics.DrawString(datalabel, new Font("Arial", 8, FontStyle.Bold), Brushes.Black, 237, 20); * * datalabel = grade; * e.Graphics.DrawString(datalabel, new Font("Arial", 8, FontStyle.Bold), Brushes.Black, 237, 35); * * datalabel = "Weight"; * e.Graphics.DrawString(datalabel, new Font("Arial", 8, FontStyle.Bold), Brushes.Black, 297, 20); * datalabel = rweight.ToString() + " (Kg)"; * e.Graphics.DrawString(datalabel, new Font("Arial", 8, FontStyle.Bold), Brushes.Black, 297, 35); * * * //e.Graphics.DrawString(datalabel, new Font("Arial", 8, FontStyle.Bold), Brushes.Black, 140, 60); * * datalabel = "Internal Lot Code"; * e.Graphics.DrawString(datalabel, new Font("Arial", 8, FontStyle.Bold), Brushes.Black, 180, 55); * * datalabel = intlotcode; * e.Graphics.DrawString(datalabel, new Font("Arial", 8, FontStyle.Bold), Brushes.Black, 180, 70); * * * datalabel = "Remark"; * e.Graphics.DrawString(datalabel, new Font("Arial", 8, FontStyle.Bold), Brushes.Black, 297, 55); * * datalabel = remark; * e.Graphics.DrawString(datalabel, new Font("Arial", 8, FontStyle.Bold), Brushes.Black, 297, 70); * * datalabel = "Origin"; * e.Graphics.DrawString(datalabel, new Font("Arial", 8, FontStyle.Bold), Brushes.Black, 180, 90); * * datalabel = origin; * e.Graphics.DrawString(datalabel, new Font("Arial", 8, FontStyle.Bold), Brushes.Black, 180, 105); * * datalabel = "Fishing Ground"; * e.Graphics.DrawString(datalabel, new Font("Arial", 8, FontStyle.Bold), Brushes.Black, 260, 90); * * datalabel = fishing_ground; * e.Graphics.DrawString(datalabel, new Font("Arial", 8, FontStyle.Bold), Brushes.Black, 260, 105); * * datalabel = "Processing Date: " + cutdatestr; * e.Graphics.DrawString(datalabel, new Font("Arial", 8, FontStyle.Bold), Brushes.Black, 180, 125); * * if (!cert.Equals("")) * { * datalabel = cert + " Code: " + certcode; * e.Graphics.DrawString(datalabel, new Font("Arial", 8, FontStyle.Bold), Brushes.Black, 180, 145); * } * * e.Graphics.DrawString(productname, new Font("Arial", 8, FontStyle.Bold), Brushes.Black, 180, 170); */ }
private void printDocument1_PrintPage(object sender, PrintPageEventArgs e) { try { StringFormat formato = new StringFormat(); formato.Alignment = StringAlignment.Near; formato.LineAlignment = StringAlignment.Near; e.Graphics.PageUnit = GraphicsUnit.Millimeter; e.PageSettings.Margins = new Margins(0, 0, 0, 0); Pen blackPen = new Pen(Color.Black, (float)0.2); Font fontNormal = new Font("Arial", 9, FontStyle.Regular); Font fontSmall = new Font("Arial", 8, FontStyle.Regular); Font fontBold = new Font("Arial", 9, FontStyle.Bold); Brush brocha = Brushes.Black; Point point1 = new Point(5, 5); Point point2 = new Point(205, 5); // e.Graphics.DrawLine(blackPen, point1, point2); point1 = new Point(5, 5); point2 = new Point(5, 274); // e.Graphics.DrawLine(blackPen, point1, point2); point1 = new Point(5, 274); point2 = new Point(205, 274); // e.Graphics.DrawLine(blackPen, point1, point2); point1 = new Point(205, 274); point2 = new Point(205, 5); // e.Graphics.DrawLine(blackPen, point1, point2); //////////////////////////////////////////////////////////////// //// row1 pictures, Tel, NFact // //////////////////////////////////////////////////////////////// int row1PosY = 12, row1Cell0PosX = 10, row1Cell1PosX = 79, row1Cell2PosX = 167; e.Graphics.DrawImage(GOLLSYSTEM.Properties.Resources.Goll_Logo_Black, row1Cell0PosX, row1PosY, 60, 24); e.Graphics.DrawImage(GOLLSYSTEM.Properties.Resources.Logo_goll_center, row1Cell1PosX, row1PosY, 60, 18); e.Graphics.DrawString("TEL.: " + GOLLSYSTEM.Properties.Settings.Default.Tel, fontSmall, brocha, row1Cell1PosX + 18, row1PosY + 15); e.Graphics.DrawImage(GOLLSYSTEM.Properties.Resources.box_bill, row1Cell2PosX, row1PosY - 5, 38, 16); // e.Graphics.DrawRectangle(new Pen(Brushes.Black, 1f), Rectangle.FromLTRB(row1Cell2PosX, row1PosY, 205, 25)); e.Graphics.DrawString(currentFactura.NFactura, fontBold, brocha, row1Cell2PosX + 10, row1PosY + 1); //////////////////////////////////////////////////////////////// //// row2 total // //////////////////////////////////////////////////////////////// int row2PosY = 36, row2Cell0PosX = 8, row2Cell1PosX = 147; e.Graphics.DrawString("RECIBO DE INGRESO", fontNormal, brocha, row2Cell0PosX, row2PosY); decimal total = 0; foreach (Detfactura det in currentFactura.DetsFactura) { total += det.Total - det.Descuento; } e.Graphics.DrawString("POR$ " + Decimal.Round(total, 2), fontNormal, brocha, row2Cell1PosX, row2PosY); point1 = new Point(row2Cell1PosX + 10, row2PosY + 4); point2 = new Point(190, row2PosY + 4); e.Graphics.DrawLine(blackPen, point1, point2); //////////////////////////////////////////////////////////////// //// row3 cliente // //////////////////////////////////////////////////////////////// int row3PosY = 48, row3Cell0PosX = 10; e.Graphics.DrawString("RECIBI DEL SR(ES): " + PersonaDAL.getPersonaById(currentFactura.IdPersona).Nombre.ToUpper(), fontNormal, brocha, row3Cell0PosX, row3PosY); point1 = new Point(row3Cell0PosX + 32, row3PosY + 4); point2 = new Point(190, row3PosY + 4); e.Graphics.DrawLine(blackPen, point1, point2); //////////////////////////////////////////////////////////////// //// row4 datos del cliente // //////////////////////////////////////////////////////////////// int row4PosY = 56, row4Cell0PosX = 10, row4Cell1PosX = 64, row4Cell2PosX = 121; e.Graphics.DrawString("TEL.:", fontNormal, brocha, row4Cell0PosX, row4PosY); point1 = new Point(row4Cell0PosX + 9, row4PosY + 4); point2 = new Point(60, row4PosY + 4); e.Graphics.DrawLine(blackPen, point1, point2); e.Graphics.DrawString("CEL.:", fontNormal, brocha, row4Cell1PosX, row4PosY); point1 = new Point(row4Cell1PosX + 10, row4PosY + 4); point2 = new Point(118, row4PosY + 4); e.Graphics.DrawLine(blackPen, point1, point2); e.Graphics.DrawString("E-MAIL.:", fontNormal, brocha, row4Cell2PosX, row4PosY); point1 = new Point(row4Cell2PosX + 14, row4PosY + 4); point2 = new Point(190, row4PosY + 4); e.Graphics.DrawLine(blackPen, point1, point2); //////////////////////////////////////////////////////////////// //// row5 cantidad de // //////////////////////////////////////////////////////////////// int row5PosY = 64, row5Cell0PosX = 10; Moneda moneda = new Moneda(); string Dolares = Decimal.Round(total, 2).ToString().Substring(0, Decimal.Round(total, 2).ToString().Length - 3); string Centavos = Decimal.Round(total, 2).ToString().Substring(Decimal.Round(total, 2).ToString().Length - 2, 2); e.Graphics.DrawString("LA CANTIDAD DE: " + moneda.Convertir(Dolares, true, "DOLARES").Substring(0, moneda.Convertir(Dolares, true, "DOLARES").Length - 6) + (Centavos == "00" ? "" : " CON " + moneda.Convertir(Centavos, true, "CENTAVOS").Substring(0, moneda.Convertir(Centavos, true, "CENTAVOS").Length - 6)), fontNormal, brocha, row5Cell0PosX, row5PosY); point1 = new Point(row5Cell0PosX + 32, row5PosY + 4); point2 = new Point(190, row5PosY + 4); e.Graphics.DrawLine(blackPen, point1, point2); //////////////////////////////////////////////////////////////// //// row6 concepto de // //////////////////////////////////////////////////////////////// int row6PosY = 72, row6Cell0PosX = 10; string concepto = ""; foreach (Detfactura det in currentFactura.DetsFactura) { concepto = concepto + (det.Producto.Nombre + (det.Tipo == "M" ? " \"" + Convert.ToDateTime(CuotaDAL.getCuotaById(det.Matricdetfac.IdCuota).FhRegistro).ToString("MMMM", new CultureInfo("es-ES")) + "\"" : "") + (currentFactura.DetsFactura.Count > 1 ? currentFactura.DetsFactura.Last().Id == det.Id ? "." : ", " : ".") + ""); } e.Graphics.DrawString("EN CONCEPTO DE: " + concepto.ToUpper(), fontNormal, brocha, row6Cell0PosX, row6PosY); point1 = new Point(row6Cell0PosX + 32, row6PosY + 4); point2 = new Point(190, row6PosY + 4); e.Graphics.DrawLine(blackPen, point1, point2); //////////////////////////////////////////////////////////////// //// row7 total // //////////////////////////////////////////////////////////////// int row7PosY = 80, row7Cell0PosX = 10, row7Cell1PosX = 64, row7Cell2PosX = 121; e.Graphics.DrawString("RESERVACION", fontNormal, brocha, row7Cell0PosX, row7PosY); e.Graphics.DrawRectangle(new Pen(Brushes.Black, 0.5f), Rectangle.FromLTRB(row7Cell0PosX + 30, row7PosY, row7Cell0PosX + 40, row7PosY + 5)); foreach (Detfactura det in currentFactura.DetsFactura) { if (det.Tipo == "R") { e.Graphics.DrawImage(GOLLSYSTEM.Properties.Resources.marca_de_verificacion, row7Cell0PosX + 33, row7PosY, 5, 5); } } e.Graphics.DrawString("MENSUALIDAD", fontNormal, brocha, row7Cell1PosX, row7PosY); e.Graphics.DrawRectangle(new Pen(Brushes.Black, 0.5f), Rectangle.FromLTRB(row7Cell1PosX + 30, row7PosY, row7Cell1PosX + 40, row7PosY + 5)); foreach (Detfactura det in currentFactura.DetsFactura) { if (det.Tipo == "M") { e.Graphics.DrawImage(GOLLSYSTEM.Properties.Resources.marca_de_verificacion, row7Cell1PosX + 33, row7PosY, 5, 5); } } e.Graphics.DrawString("CANCELACION", fontNormal, brocha, row7Cell2PosX, row7PosY); e.Graphics.DrawRectangle(new Pen(Brushes.Black, 0.5f), Rectangle.FromLTRB(row7Cell2PosX + 30, row7PosY, row7Cell2PosX + 40, row7PosY + 5)); foreach (Detfactura det in currentFactura.DetsFactura) { if (det.Tipo == "C" || det.Tipo == "F") { e.Graphics.DrawImage(GOLLSYSTEM.Properties.Resources.marca_de_verificacion, row7Cell2PosX + 33, row7PosY, 5, 5); } } //////////////////////////////////////////////////////////////// //// row8 Observacion // //////////////////////////////////////////////////////////////// int row8PosY = 89, row8Cell0PosX = 10; string Obs1 = ""; string Obs2 = ""; string Obs3 = ""; char[] letras = currentFactura.Observacion.ToArray(); foreach (char letra in letras) { if (Obs1.Length < 81) { Obs1 += letra; } else if (Obs2.Length < 91) { Obs2 += letra; } else if (Obs3.Length < 91) { Obs3 += letra; } } e.Graphics.DrawString("OBSERVACION ", fontNormal, brocha, row8Cell0PosX, row8PosY); point1 = new Point(row8Cell0PosX + 28, row8PosY + 4); point2 = new Point(190, row8PosY + 4); e.Graphics.DrawLine(blackPen, point1, point2); e.Graphics.DrawString(Obs1.ToUpper(), fontSmall, brocha, row8Cell0PosX + 28, row8PosY); point1 = new Point(row8Cell0PosX, row8PosY + 4 + 7); point2 = new Point(190, row8PosY + 4 + 7); e.Graphics.DrawLine(blackPen, point1, point2); e.Graphics.DrawString(Obs2.ToUpper(), fontSmall, brocha, row8Cell0PosX, row8PosY + 7); point1 = new Point(row8Cell0PosX, row8PosY + 4 + 7 + 7); point2 = new Point(190, row8PosY + 4 + 7 + 7); e.Graphics.DrawLine(blackPen, point1, point2); e.Graphics.DrawString(Obs3.ToUpper(), fontSmall, brocha, row8Cell0PosX, row8PosY + 7 + 7); //////////////////////////////////////////////////////////////// //// row9 mora // //////////////////////////////////////////////////////////////// int row9PosY = 110, row9Cell0PosX = 57; e.Graphics.DrawString("NOTA: DESPUES DE " + Properties.Settings.Default.DaysMora + " DIAS SE COBRARA $" + Properties.Settings.Default.Mora + " POR MORA", fontNormal, brocha, row9Cell0PosX, row9PosY); //////////////////////////////////////////////////////////////// //// row10 recibo, fwcha // //////////////////////////////////////////////////////////////// int row10PosY = 128, row10Cell0PosX = 14, row10Cell1PosX = 149; point1 = new Point(row10Cell0PosX, row10PosY); point2 = new Point(54, row10PosY); e.Graphics.DrawLine(blackPen, point1, point2); e.Graphics.DrawString("RECIBO", fontNormal, brocha, row10Cell0PosX + 13, row10PosY + 1); point1 = new Point(row10Cell1PosX, row10PosY); point2 = new Point(190, row10PosY); e.Graphics.DrawLine(blackPen, point1, point2); e.Graphics.DrawString(YearDAL.getServerDate().ToString("dd/MM/yyyy"), fontBold, brocha, row10Cell1PosX + 11, row10PosY - 4); e.Graphics.DrawString("FECHA", fontNormal, brocha, row10Cell1PosX + 14, row10PosY + 1); //////////////////////////////////////////////////////////////// //// Duplicado // //////////////////////////////////////////////////////////////// point1 = new Point(5, 137); point2 = new Point(205, 137); e.Graphics.DrawLine(blackPen, point1, point2); int duplicatedTop = 137; //////////////////////////////////////////////////////////////// //// row1 pictures, Tel, NFact // //////////////////////////////////////////////////////////////// row1PosY = 12 + duplicatedTop; e.Graphics.DrawImage(GOLLSYSTEM.Properties.Resources.Goll_Logo_Black, row1Cell0PosX, row1PosY, 60, 24); e.Graphics.DrawImage(GOLLSYSTEM.Properties.Resources.Logo_goll_center, row1Cell1PosX, row1PosY, 60, 18); e.Graphics.DrawString("TEL.: " + GOLLSYSTEM.Properties.Settings.Default.Tel, fontNormal, brocha, row1Cell1PosX + 18, row1PosY + 15); e.Graphics.DrawImage(GOLLSYSTEM.Properties.Resources.box_bill, row1Cell2PosX, row1PosY - 5, 38, 16); // e.Graphics.DrawRectangle(new Pen(Brushes.Black, 1f), Rectangle.FromLTRB(row1Cell2PosX, row1PosY, 205, 25)); e.Graphics.DrawString(currentFactura.NFactura, fontBold, brocha, row1Cell2PosX + 10, row1PosY + 1); //////////////////////////////////////////////////////////////// //// row2 total // //////////////////////////////////////////////////////////////// row2PosY = 36 + duplicatedTop; e.Graphics.DrawString("RECIBO DE INGRESO", fontNormal, brocha, row2Cell0PosX, row2PosY); e.Graphics.DrawString("POR$ " + Decimal.Round(total, 2), fontNormal, brocha, row2Cell1PosX, row2PosY); point1 = new Point(row2Cell1PosX + 10, row2PosY + 4); point2 = new Point(190, row2PosY + 4); e.Graphics.DrawLine(blackPen, point1, point2); //////////////////////////////////////////////////////////////// //// row3 cliente // //////////////////////////////////////////////////////////////// row3PosY = 48 + duplicatedTop; e.Graphics.DrawString("RECIBI DEL SR(ES): " + PersonaDAL.getPersonaById(currentFactura.IdPersona).Nombre.ToUpper(), fontNormal, brocha, row3Cell0PosX, row3PosY); point1 = new Point(row3Cell0PosX + 32, row3PosY + 4); point2 = new Point(190, row3PosY + 4); e.Graphics.DrawLine(blackPen, point1, point2); //////////////////////////////////////////////////////////////// //// row4 datos del cliente // //////////////////////////////////////////////////////////////// row4PosY = 56 + duplicatedTop; e.Graphics.DrawString("TEL.:", fontNormal, brocha, row4Cell0PosX, row4PosY); point1 = new Point(row4Cell0PosX + 9, row4PosY + 4); point2 = new Point(60, row4PosY + 4); e.Graphics.DrawLine(blackPen, point1, point2); e.Graphics.DrawString("CEL.:", fontNormal, brocha, row4Cell1PosX, row4PosY); point1 = new Point(row4Cell1PosX + 10, row4PosY + 4); point2 = new Point(118, row4PosY + 4); e.Graphics.DrawLine(blackPen, point1, point2); e.Graphics.DrawString("E-MAIL.:", fontNormal, brocha, row4Cell2PosX, row4PosY); point1 = new Point(row4Cell2PosX + 14, row4PosY + 4); point2 = new Point(190, row4PosY + 4); e.Graphics.DrawLine(blackPen, point1, point2); //////////////////////////////////////////////////////////////// //// row5 cantidad de // //////////////////////////////////////////////////////////////// row5PosY = 64 + duplicatedTop; e.Graphics.DrawString("LA CANTIDAD DE: " + moneda.Convertir(Dolares, true, "DOLARES").Substring(0, moneda.Convertir(Dolares, true, "DOLARES").Length - 6) + (Centavos == "00" ? "" : " CON " + moneda.Convertir(Centavos, true, "CENTAVOS").Substring(0, moneda.Convertir(Centavos, true, "CENTAVOS").Length - 6)), fontNormal, brocha, row5Cell0PosX, row5PosY); point1 = new Point(row5Cell0PosX + 32, row5PosY + 4); point2 = new Point(190, row5PosY + 4); e.Graphics.DrawLine(blackPen, point1, point2); //////////////////////////////////////////////////////////////// //// row6 concepto de // //////////////////////////////////////////////////////////////// row6PosY = 72 + duplicatedTop; e.Graphics.DrawString("EN CONCEPTO DE: " + concepto.ToUpper(), fontNormal, brocha, row6Cell0PosX, row6PosY); point1 = new Point(row6Cell0PosX + 32, row6PosY + 4); point2 = new Point(190, row6PosY + 4); e.Graphics.DrawLine(blackPen, point1, point2); //////////////////////////////////////////////////////////////// //// row7 total // //////////////////////////////////////////////////////////////// row7PosY = 80 + duplicatedTop; e.Graphics.DrawString("RESERVACION", fontNormal, brocha, row7Cell0PosX, row7PosY); e.Graphics.DrawRectangle(new Pen(Brushes.Black, 0.5f), Rectangle.FromLTRB(row7Cell0PosX + 30, row7PosY, row7Cell0PosX + 40, row7PosY + 5)); foreach (Detfactura det in currentFactura.DetsFactura) { if (det.Tipo == "R") { e.Graphics.DrawImage(GOLLSYSTEM.Properties.Resources.marca_de_verificacion, row7Cell0PosX + 33, row7PosY, 5, 5); } } e.Graphics.DrawString("MENSUALIDAD", fontNormal, brocha, row7Cell1PosX, row7PosY); e.Graphics.DrawRectangle(new Pen(Brushes.Black, 0.5f), Rectangle.FromLTRB(row7Cell1PosX + 30, row7PosY, row7Cell1PosX + 40, row7PosY + 5)); foreach (Detfactura det in currentFactura.DetsFactura) { if (det.Tipo == "M") { e.Graphics.DrawImage(GOLLSYSTEM.Properties.Resources.marca_de_verificacion, row7Cell1PosX + 33, row7PosY, 5, 5); } } e.Graphics.DrawString("CANCELACION", fontNormal, brocha, row7Cell2PosX, row7PosY); e.Graphics.DrawRectangle(new Pen(Brushes.Black, 0.5f), Rectangle.FromLTRB(row7Cell2PosX + 30, row7PosY, row7Cell2PosX + 40, row7PosY + 5)); foreach (Detfactura det in currentFactura.DetsFactura) { if (det.Tipo == "C" || det.Tipo == "F") { e.Graphics.DrawImage(GOLLSYSTEM.Properties.Resources.marca_de_verificacion, row7Cell2PosX + 33, row7PosY, 5, 5); } } //////////////////////////////////////////////////////////////// //// row8 Observacion // //////////////////////////////////////////////////////////////// row8PosY = 89 + duplicatedTop; e.Graphics.DrawString("OBSERVACION ", fontNormal, brocha, row8Cell0PosX, row8PosY); point1 = new Point(row8Cell0PosX + 28, row8PosY + 4); point2 = new Point(190, row8PosY + 4); e.Graphics.DrawLine(blackPen, point1, point2); e.Graphics.DrawString(Obs1.ToUpper(), fontSmall, brocha, row8Cell0PosX + 28, row8PosY); point1 = new Point(row8Cell0PosX, row8PosY + 4 + 7); point2 = new Point(190, row8PosY + 4 + 7); e.Graphics.DrawLine(blackPen, point1, point2); e.Graphics.DrawString(Obs2.ToUpper(), fontSmall, brocha, row8Cell0PosX, row8PosY + 7); point1 = new Point(row8Cell0PosX, row8PosY + 4 + 7 + 7); point2 = new Point(190, row8PosY + 4 + 7 + 7); e.Graphics.DrawLine(blackPen, point1, point2); e.Graphics.DrawString(Obs3.ToUpper(), fontSmall, brocha, row8Cell0PosX, row8PosY + 7 + 7); //////////////////////////////////////////////////////////////// //// row9 mora // //////////////////////////////////////////////////////////////// row9PosY = 110 + duplicatedTop; e.Graphics.DrawString("NOTA: DESPUES DE " + Properties.Settings.Default.DaysMora + " DIAS SE COBRARA $" + Properties.Settings.Default.Mora + " POR MORA", fontNormal, brocha, row9Cell0PosX, row9PosY); //////////////////////////////////////////////////////////////// //// row10 recibo, fwcha // //////////////////////////////////////////////////////////////// row10PosY = 128 + duplicatedTop; point1 = new Point(row10Cell0PosX, row10PosY); point2 = new Point(54, row10PosY); e.Graphics.DrawLine(blackPen, point1, point2); e.Graphics.DrawString("RECIBO", fontNormal, brocha, row10Cell0PosX + 13, row10PosY + 1); point1 = new Point(row10Cell1PosX, row10PosY); point2 = new Point(190, row10PosY); e.Graphics.DrawLine(blackPen, point1, point2); e.Graphics.DrawString(YearDAL.getServerDate().ToString("dd/MM/yyyy"), fontBold, brocha, row10Cell1PosX + 11, row10PosY - 4); e.Graphics.DrawString("FECHA", fontNormal, brocha, row10Cell1PosX + 14, row10PosY + 1); } catch (Exception ex) { MessageBox.Show("Error: " + ex.ToString()); } }
private void printDocument1_PrintPage(object sender, PrintPageEventArgs e) { imp.Impresion(printDocument1, e); }
public void PrintDocument_PrintPage(object sender, PrintPageEventArgs e) { // we do not use the buffers when printing (the printer is probably higher-resolution!) Graphics gr = e.Graphics; Page page = CurrentDocument.Page(m_PrintPageIndex); e.PageSettings.Landscape = page.IsLandscape; gr.ResetTransform(); gr.PageUnit = GraphicsUnit.Pixel; // GraphicsUnit.Millimeter ' it shows 600 DPI which makes the usual scaling conversion for mono impossible SizeF printable = e.PageSettings.PrintableArea.Size.MultiplyBy(Geometry.INCH / 100); // in mm. Apparently e.MarginBounds or e.PageSettings.PrintableArea is in hundredths of an inch (?) if (page.IsLandscape) { printable = printable.Flip(); // But sadly e.PageSettings.PrintableArea does not account for orientation } var pageSize = page.Size; // max scale that will fit: var scale = Math.Min(printable.Width / pageSize.Width, printable.Height / pageSize.Height); if (scale > 0.97f) // will not fit at full size (allow a bit <1 in case of slight margin issues) { scale = 1; // don't shrink } else { pageSize.Width *= scale; // update page size for centreing below pageSize.Height *= scale; } gr.ScaleTransform(scale * gr.DpiX / Geometry.INCH, scale * gr.DpiY / Geometry.INCH); gr.TranslateTransform(0, page.Size.Height - 1); // centre it gr.TranslateTransform(scale * (pageSize.Width - pageSize.Width) / 2, scale * (pageSize.Height - pageSize.Height) / 2); // No need to take account of the margins if we are centring it anyway //gr.TranslateTransform(m_objPage.Margin - INCH * e.PageSettings.HardMarginX / 100, m_objPage.Margin - INCH * e.PageSettings.HardMarginY / 100) gr.SmoothingMode = SmoothingMode.AntiAlias; gr.TextRenderingHint = TextRenderingHint.AntiAlias; // otherwise text on transparent buffer is naff using (NetCanvas canvas = new NetCanvas(gr, true)) { page.DrawBackground(canvas, scale * gr.DpiX / Geometry.INCH, page.Paper.PrintBackground, false); if (page != CurrentPage) { page.BackgroundImage?.Release(); // avoid overload if document has masses of large pages } if (e.PageSettings.PrinterSettings.PrintRange == PrintRange.Selection) { page.DrawSelected(canvas, null, scale, gr.DpiX / Geometry.INCH, true); } else { page.DrawShapes(canvas, scale, gr.DpiX / Geometry.INCH, null, !PrintMeasures); } } m_PrintPageIndex += 1; switch (m_PrintDocument.PrinterSettings.PrintRange) { case PrintRange.CurrentPage: case PrintRange.Selection: e.HasMorePages = false; break; default: e.HasMorePages = m_PrintPageIndex + 1 <= m_PrintDocument.PrinterSettings.ToPage; // +1 is the conversion from 0-based to 1-based break; } }
public void printdoc_printpage(object sender, PrintPageEventArgs e) { Rectangle pagearea = e.PageBounds; e.Graphics.DrawImage(memoryimg, (pagearea.Width / 2) - (this.panel1.Width / 2), this.panel1.Location.Y); }
// The function that prints the title and header row private void drawHeader(PrintPageEventArgs e) { //initialize local fields _cellHeight = (int)_bodyFont.Height + 5; // set cell height _column1.X = e.MarginBounds.Left; _column1.Y = e.MarginBounds.Top; _column2.X = e.MarginBounds.Left + e.MarginBounds.Width / 2; _column2.Y = e.MarginBounds.Top; //Draw Header e.Graphics.DrawString(_headerText, _headerFont, Brushes.Black, _column1.X, _column1.Y - 20); //Draw Date e.Graphics.DrawString(DateTime.Now.ToLongDateString(), _headerFont, Brushes.Black, _column2.X, _column2.Y - 20); drawRow(e.Graphics); // reset Column Points _column1.Y += _cellHeight; _column2.Y += _cellHeight; }
private void prepareTicket(object sender, PrintPageEventArgs e) { /*int width = (int)this.printDialog1.PrinterSettings.DefaultPageSettings.PrintableArea.Width; * int num1 = 0; * Graphics graphics = e.Graphics; * string str1 = string.Format("Faltantes {0}", (object)this.depot.name); * Font font1 = this.fitFont(str1, width, FontStyle.Bold); * Size stringSize1 = this.getStringSize(str1, font1); * graphics.DrawString(str1, font1, Brushes.Black, (float)((width - stringSize1.Width) / 2), (float)num1); * int num2 = num1 + (stringSize1.Height + 5); * string str2 = "Cantidad"; * Font font2 = new Font("Times new roman", 12f); * Size stringSize2 = this.getStringSize(str2, font2); * graphics.DrawLine(Pens.Black, 10, num2, this.Width - 10, num2); * int num3 = num2 + 2; * graphics.DrawString("Producto", font2, Brushes.Black, 0.0f, (float)num3); * graphics.DrawString(str2, font2, Brushes.Black, (float)(width - stringSize2.Width), (float)num3); * int num4 = num3 + (stringSize2.Height + 2); * graphics.DrawLine(Pens.Black, 10, num4, this.Width - 10, num4); * int num5 = num4 + 2; * /* DataTable checkboxes = new DataTable(); * * checkboxes.Columns.Add("barcode"); * checkboxes.Columns.Add("isChecked"); * * * * foreach (DataGridViewRow row in this.dataGrid1.Rows) * { * if (Convert.ToBoolean(row.Cells["Print"].Value)) * { * Producto producto = new Producto(row.Cells["Código de Barras"].Value.ToString()); * Font font3 = font2; * string str3 = string.Format("{0}\n{1}", (object)producto.Description, (object)producto.Brand); * string str4 = row.Cells["Cantidad Faltante"].Value.ToString(); * Size stringSize3 = this.getStringSize(str3, font3); * Size stringSize4 = this.getStringSize(str4, font3); * if (stringSize3.Width > width / 2) * { * font3 = this.fitFont(str3, width * 3 / 4 - 5, FontStyle.Regular); * stringSize3 = this.getStringSize(str3, font3); * stringSize4 = this.getStringSize(str4, font3); * } * graphics.DrawString(str3, font3, Brushes.Black, 0.0f, (float)num5); * graphics.DrawString(str4, font3, Brushes.Black, (float)(width - stringSize4.Width), (float)num5); * if (row.Index % 2 == 0) * { * SolidBrush solidBrush = new SolidBrush(Color.FromArgb(242, 242, 242)); * graphics.FillRectangle((Brush)solidBrush, 0, num5, 0, num5 + stringSize3.Height); * } * graphics.DrawLine(Pens.Black, 10, num5, this.Width - 10, num5); * num5 += 3 + stringSize3.Height; * } * * DataRow r = checkboxes.NewRow(); * r[0] = row.Cells[1].Value.ToString(); * r[1] = Convert.ToBoolean(row.Cells["Print"].Value); * * checkboxes.Rows.Add(r); * } * * * Bodega.updateProductCheckStatus(depot.ID, checkboxes);*/ }
private bool printResult(PrintPageEventArgs ev, ref float yPos, int tab) { int nrOfLinesThisResult = 1; bool printThisCompetitor = true; printHeader(ev, ref yPos, tab); printHeaderIndividual(ev, ref yPos, tab); competitorsDone++; int place = competitorsDone; for (int i = competitorsDone; i <= results.GetUpperBound(0); i++) { if (this.clubId != null) { if (this.clubId != results[i].ClubId) { printThisCompetitor = false; } else { printThisCompetitor = true; } } if (printThisCompetitor) { place++; nrOfLinesThisResult = 1; // If this competitor would print outsite margins, return // and wait for next page. if (yPos + 2 * printCompetitorFont.GetHeight() > ev.MarginBounds.Bottom) { return(true); } // Print this competitor ev.Graphics.DrawString((place).ToString(), printCompetitorFont, Brushes.Black, this.colIndividPlace, yPos, new StringFormat()); //ev.Graphics.DrawString(results[i].ShooterName, // printCompetitorFont, Brushes.Black, this.colIndividName, yPos, // new StringFormat()); printString(ev, results[i].ShooterName, printCompetitorFont, this.colIndividName, yPos, colIndividResult - colIndividClub); //ev.Graphics.DrawString(CommonCode.GetClub(results[i].ClubId).Name, // printCompetitorFont, Brushes.Black, this.colIndividClub, yPos, // new StringFormat()); printString(ev, CommonCode.GetClub(results[i].ClubId).Name, printCompetitorFont, this.colIndividClub, yPos, colIndividResult - colIndividClub); float xPosHitsPerStn = this.colIndividResult; foreach (string strnTemp in results[i].HitsPerStnString.Split(';')) { string strn = strnTemp; if (xPosHitsPerStn + ev.Graphics.MeasureString(strn, printCompetitorFont).Width > colIndividResultMaxWidth) { nrOfLinesThisResult++; xPosHitsPerStn = this.colIndividResult; } if (strn != "") { switch (CompetitionType) { case Structs.CompetitionTypeEnum.Field: if (!competition.NorwegianCount) { string[] parts = strn.Split('/'); int hits = int.Parse(parts[0]); int figures = int.Parse(parts[1]); strn = hits.ToString(); } else { /*string[] parts = strn.Split('/'); * int hits = int.Parse(parts[0]); * int figures = int.Parse(parts[1]); * strn = (hits + figures).ToString();*/ } break; case Structs.CompetitionTypeEnum.MagnumField: if (!competition.NorwegianCount) { string[] parts = strn.Split('/'); int hits = int.Parse(parts[0]); int figures = int.Parse(parts[1]); strn = hits.ToString(); } else { string[] parts = strn.Split('/'); int hits = int.Parse(parts[0]); int figures = int.Parse(parts[1]); strn = (hits + figures).ToString(); } break; case Structs.CompetitionTypeEnum.Precision: break; } } ev.Graphics.DrawString(strn, printCompetitorFont, Brushes.Black, xPosHitsPerStn, yPos + (nrOfLinesThisResult - 1) * printCompetitorHeaderFont.GetHeight(), new StringFormat()); xPosHitsPerStn += ev.Graphics.MeasureString(strn + " ", printCompetitorFont).Width; } if (results[i].FinalShootingPlace < 100 & results[i].FinalShootingPlace > 0) { string strn = "(" + results[i].FinalShootingPlace.ToString() + ")"; if (xPosHitsPerStn + ev.Graphics.MeasureString(strn, printCompetitorFont).Width > colIndividResultMaxWidth) { nrOfLinesThisResult++; xPosHitsPerStn = this.colIndividResult; } ev.Graphics.DrawString(strn, printCompetitorFont, Brushes.Black, xPosHitsPerStn, yPos + (nrOfLinesThisResult - 1) * printCompetitorHeaderFont.GetHeight(), new StringFormat()); } string resultString = ""; switch (CompetitionType) { case Structs.CompetitionTypeEnum.Field: { if (competition.NorwegianCount) { resultString = (results[i].HitsTotal + results[i].FigureHitsTotal).ToString(); } else { resultString = results[i].HitsTotal + "/" + results[i].FigureHitsTotal; } ev.Graphics.DrawString(results[i].PointsTotal.ToString(), printCompetitorFont, Brushes.Black, this.colIndividPoints, yPos, new StringFormat()); break; } case Structs.CompetitionTypeEnum.MagnumField: { resultString = results[i].HitsTotal + "/" + results[i].FigureHitsTotal; ev.Graphics.DrawString(results[i].PointsTotal.ToString(), printCompetitorFont, Brushes.Black, this.colIndividPoints, yPos, new StringFormat()); break; } case Structs.CompetitionTypeEnum.Precision: { resultString = results[i].HitsTotal.ToString(); break; } default: throw new ApplicationException("Unknown CompetitionType"); } ev.Graphics.DrawString(resultString, printCompetitorFont, Brushes.Black, this.colIndividResultTot, yPos, new StringFormat()); string medalToPrint = ""; if (results[i].Medal == Structs.Medal.StandardSilver) { medalToPrint = "S"; } else if (results[i].Medal == Structs.Medal.StardardBrons) { medalToPrint = "B"; } else { medalToPrint = ""; } ev.Graphics.DrawString(medalToPrint, printCompetitorFont, Brushes.Black, this.colIndividStdMed, yPos, new StringFormat()); if (!printPrelResults & CommonCode.GetCompetitions()[0].UsePriceMoney & results[i].PriceMoney > 0) { ev.Graphics.DrawString(results[i].PriceMoney.ToString() + ":-", printCompetitorFont, Brushes.Black, this.colIndividPrice, yPos, new StringFormat()); } // Ok, done printing. Draw line beneath the shooter. ev.Graphics.DrawLine(new Pen(Brushes.Black, 1), new PointF(this.LeftMargin, yPos - 1), new PointF(this.RightMargin, yPos - 1)); // Prepare for the next shooter yPos += nrOfLinesThisResult * printCompetitorHeaderFont.GetHeight(); competitorsDone = i; // If there is more shooters to print out and no more room if (yPos + nrOfLinesThisResult * printCompetitorHeaderFont.GetHeight() > ev.MarginBounds.Bottom) { competitorsDone++; return(true); } } } return(moreClassesPages()); }
/// <summary> /// 打印文档 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void m_PrintDocument_PrintPage(object sender, PrintPageEventArgs e) { //if (m_PageIndex == 1) //{ // if (m_PrintDocument.DefaultPageSettings.PaperSize.Kind == PaperKind.A4) // { // e.Graphics.DrawImage(util.MF1, new RectangleF(5, 0, util.m_PageWidth * 0.98f, util.m_PageHeight * 0.98f));//x 10 // } // else if (m_PrintDocument.DefaultPageSettings.PaperSize.Kind == PaperKind.B5) // { // e.Graphics.DrawImage(util.MF1, new RectangleF(5, 0, util.m_PageWidth * 0.88f, util.m_PageHeight * 0.88f)); // } // else if (m_PrintDocument.DefaultPageSettings.PaperSize.Kind == PaperKind.Custom) // { // e.Graphics.DrawImage(util.MF1, new RectangleF(30, 0, util.m_PageWidth * 0.90f, util.m_PageHeight * 0.90f)); // } // m_PageIndex++; // e.HasMorePages = true; //} //else if (m_PageIndex == 2) //{ // if (m_PrintDocument.DefaultPageSettings.PaperSize.Kind == PaperKind.A4) // { // e.Graphics.DrawImage(util.MF2, new RectangleF(5, 0, util.m_PageWidth * 0.98f, util.m_PageHeight * 0.98f));//10 // } // else if (m_PrintDocument.DefaultPageSettings.PaperSize.Kind == PaperKind.B5) // { // e.Graphics.DrawImage(util.MF2, new RectangleF(5, 0, util.m_PageWidth * 0.88f, util.m_PageHeight * 0.88f)); // } // else if (m_PrintDocument.DefaultPageSettings.PaperSize.Kind == PaperKind.Custom) // { // e.Graphics.DrawImage(util.MF2, new RectangleF(30, 0, util.m_PageWidth * 0.90f, util.m_PageHeight * 0.90f)); // } // m_PageIndex = 1; // e.HasMorePages = false; //} if (cmbPrintPage.SelectedText == "打印第一页") { if (m_PrintDocument.DefaultPageSettings.PaperSize.Kind == PaperKind.A4) { e.Graphics.DrawImage(util.MF1, new RectangleF(5, 0, util.m_PageWidth * 0.98f, util.m_PageHeight * 0.98f));//10 } else if (m_PrintDocument.DefaultPageSettings.PaperSize.Kind == PaperKind.B5) { e.Graphics.DrawImage(util.MF1, new RectangleF(5, 0, util.m_PageWidth * 0.88f, util.m_PageHeight * 0.88f)); } else if (m_PrintDocument.DefaultPageSettings.PaperSize.Kind == PaperKind.Custom) { e.Graphics.DrawImage(util.MF1, new RectangleF(30, 0, util.m_PageWidth * 0.90f, util.m_PageHeight * 0.90f)); } //m_PageIndex++; m_PageIndex = 1; e.HasMorePages = false; } if (cmbPrintPage.SelectedText == "打印第二页") { if (m_PrintDocument.DefaultPageSettings.PaperSize.Kind == PaperKind.A4) { e.Graphics.DrawImage(util.MF2, new RectangleF(5, 0, util.m_PageWidth * 0.98f, util.m_PageHeight * 0.98f));//10 } else if (m_PrintDocument.DefaultPageSettings.PaperSize.Kind == PaperKind.B5) { e.Graphics.DrawImage(util.MF2, new RectangleF(5, 0, util.m_PageWidth * 0.88f, util.m_PageHeight * 0.88f)); } else if (m_PrintDocument.DefaultPageSettings.PaperSize.Kind == PaperKind.Custom) { e.Graphics.DrawImage(util.MF2, new RectangleF(30, 0, util.m_PageWidth * 0.90f, util.m_PageHeight * 0.90f)); } //m_PageIndex++; m_PageIndex = 2; e.HasMorePages = false; } if (cmbPrintPage.SelectedText == "全部打印" || cmbPrintPage.SelectedText == "") { if (m_PageIndex == 1) { if (m_PrintDocument.DefaultPageSettings.PaperSize.Kind == PaperKind.A4) { e.Graphics.DrawImage(util.MF1, new RectangleF(5, 0, util.m_PageWidth * 0.98f, util.m_PageHeight * 0.98f));//10 } else if (m_PrintDocument.DefaultPageSettings.PaperSize.Kind == PaperKind.B5) { e.Graphics.DrawImage(util.MF1, new RectangleF(5, 0, util.m_PageWidth * 0.88f, util.m_PageHeight * 0.88f)); } else if (m_PrintDocument.DefaultPageSettings.PaperSize.Kind == PaperKind.Custom) { e.Graphics.DrawImage(util.MF1, new RectangleF(30, 0, util.m_PageWidth * 0.90f, util.m_PageHeight * 0.90f)); } m_PageIndex++; e.HasMorePages = true; } else if (m_PageIndex == 2) { if (m_PrintDocument.DefaultPageSettings.PaperSize.Kind == PaperKind.A4) { e.Graphics.DrawImage(util.MF2, new RectangleF(5, 0, util.m_PageWidth * 0.98f, util.m_PageHeight * 0.98f));//10 } else if (m_PrintDocument.DefaultPageSettings.PaperSize.Kind == PaperKind.B5) { e.Graphics.DrawImage(util.MF2, new RectangleF(5, 0, util.m_PageWidth * 0.88f, util.m_PageHeight * 0.88f)); } else if (m_PrintDocument.DefaultPageSettings.PaperSize.Kind == PaperKind.Custom) { e.Graphics.DrawImage(util.MF2, new RectangleF(30, 0, util.m_PageWidth * 0.90f, util.m_PageHeight * 0.90f)); } m_PageIndex = 1; e.HasMorePages = false; } } }
static private void PrintPageEvent (object sender, PrintPageEventArgs e) { e.Graphics.DrawRectangle (Pens.Red, e.MarginBounds); e.Graphics.DrawRectangle (Pens.Green, e.PageBounds); e.HasMorePages = false; }
// Event that is emitted at the start of a page. public virtual Graphics OnStartPage (PrintDocument document, PrintPageEventArgs e) { // Nothing to do here. return null; }
//Override the OnPrintPage to provide the printing logic for the document protected override void OnPrintPage(PrintPageEventArgs ev) { PrintDocumentStd printSettings = CommonCode.Settings.PrinterSettings.PaperResultDocument; printSettings.DocumentSizeXPixels = ev.PageBounds.Width; printSettings.DocumentSizeYPixels = ev.PageBounds.Height; this.RightMargin = ev.PageBounds.Right - 50; this.LeftMargin = 50; base.OnPrintPage(ev); float topMargin = ev.PageBounds.Top + 45; // Org = 25 float yPos = topMargin; float width = this.RightMargin - this.LeftMargin; colIndividPlace = LeftMargin; colIndividName = colIndividPlace + printSettings.Columns[0].SizeDpi; colIndividClub = colIndividName + printSettings.Columns[1].SizeDpi; colIndividResult = colIndividClub + printSettings.Columns[2].SizeDpi; colIndividResultTot = colIndividResult + printSettings.Columns[3].SizeDpi; colIndividPoints = colIndividResultTot + printSettings.Columns[4].SizeDpi; colIndividStdMed = colIndividPoints + printSettings.Columns[5].SizeDpi; colIndividPrice = colIndividStdMed + printSettings.Columns[6].SizeDpi; colIndividResultMaxWidth = colIndividResultTot; PrintDocumentStd printTeamSettings = CommonCode.Settings.PrinterSettings.PaperResultTeamDocument; printTeamSettings.DocumentSizeXPixels = ev.PageBounds.Width; printTeamSettings.DocumentSizeYPixels = ev.PageBounds.Height; colTeamPlace = LeftMargin; colTeamClub = colTeamPlace + printTeamSettings.Columns[0].SizeDpi; colTeamName = colTeamClub + printTeamSettings.Columns[1].SizeDpi; colTeamResult = colTeamName + printTeamSettings.Columns[2].SizeDpi; colTeamResultTot = colTeamResult + printTeamSettings.Columns[3].SizeDpi; colTeamPoints = colTeamResultTot + printTeamSettings.Columns[4].SizeDpi; colTeamResultMaxWidth = colTeamResultTot; int tab = 140; if (individualsPrintDone == false) { printIndividual(ev, ref yPos, tab); if (ev.HasMorePages == false) { individualsPrintDone = true; if (CommonCode.ResultsGetTeams(this.wclass, this.competition).Length > 0) { ev.HasMorePages = true; } } } else { // Print teams. ev.HasMorePages = printTeamResults(ev, ref yPos, tab); } }
void printDoc_PrintPage(object sender, PrintPageEventArgs e) { PrintBody(e.Graphics); }
private void printDocument1_PrintPage_1(object sender, PrintPageEventArgs e) { e.Graphics.DrawImage(bitmap, 0, 0); }
void document_PrintPage(object sender, PrintPageEventArgs e) { e.Graphics.DrawString(codeBox.Text, new Font("Arial", 20, FontStyle.Regular), Brushes.Black, 20, 20); }
protected override void OnPrintPage(PrintPageEventArgs e) { base.OnPrintPage(e); Single pagewidth = e.MarginBounds.Width * 3.0f; Single pageheight = e.MarginBounds.Height * 3.0f; Single textwidth = 0.0f; Single textheight = 0.0f; Single offsetx = e.MarginBounds.Left * 3.0f; Single offsety = e.MarginBounds.Top * 3.0f; Single x = offsetx; Single y = offsety; StringBuilder line = new StringBuilder(256); StringFormat sf = StringFormat.GenericTypographic; sf.FormatFlags = StringFormatFlags.DisplayFormatControl; sf.SetTabStops(0.0f, new Single[]{300.0f}); RectangleF r; Graphics g = e.Graphics; g.PageUnit = GraphicsUnit.Document; SizeF size = g.MeasureString("X", _font, 1, sf); Single lineheight = size.Height; // make sure we can print at least 1 line (font too big?) if (lineheight + (lineheight * 3) > pageheight) { // cannot print at least 1 line and footer g.Dispose(); e.HasMorePages = false; return; } // don't include footer pageheight -= lineheight * 3; // last whitespace in line buffer Int32 lastws = -1; // next character Int32 c = Eos; for (;;) { // get next character c = NextChar(); // append c to line if not NewLine or Eos if ((c != NewLine) && (c != Eos)) { Char ch = Convert.ToChar(c); line.Append(ch); // if ch is whitespace, remember pos and continue if (ch == ' ' || ch == '\t') { lastws = line.Length - 1; continue; } } // measure string if line is not empty if (line.Length > 0) { size = g.MeasureString(line.ToString(), _font, Int32.MaxValue, StringFormat.GenericTypographic); textwidth = size.Width; } // draw line if line is full, if NewLine or if last line if (c == Eos || (textwidth > pagewidth) || (c == NewLine)) { if (textwidth > pagewidth) { if (lastws != -1) { _offset -= line.Length - lastws - 1; line.Length = lastws + 1; } else { line.Length--; _offset--; } } // there's something to draw if (line.Length > 0) { r = new RectangleF(x, y, pagewidth, lineheight); sf.Alignment = StringAlignment.Near; g.DrawString(line.ToString(), _font, Brushes.Black, r, sf); } // increase ypos y += lineheight; textheight += lineheight; // empty line buffer line.Length = 0; textwidth = 0.0f; lastws = -1; } // if next line doesn't fit on page anymore, exit loop if (textheight > (pageheight - lineheight)) break; if (c == Eos) break; } // print footer x = offsetx; y = offsety + pageheight + (lineheight * 2); r = new RectangleF(x, y, pagewidth, lineheight); sf.Alignment = StringAlignment.Center; g.DrawString(_pageno.ToString(), _font, Brushes.Black, r, sf); g.Dispose(); _pageno++; e.HasMorePages = (c != Eos); }
protected override void OnPrintPage(PrintPageEventArgs e) { base.OnPrintPage(e); if (m_PageCount == 0) { m_HeaderHeight = this.GetHeaderHeight(e.Graphics); m_TitleHeight = this.GetTitleHeight(e.Graphics); m_FooterHeight = this.GetFooterHeight(e.Graphics); m_PageCount = this.PrecalculatePageCount(e); m_PageNo = 1; } if (m_RangeToPrint.IsEmpty()) { return; } if (m_BorderPen == null) { m_BorderPen = new Pen(Color.Black); } RectangleF area = new RectangleF(e.MarginBounds.Left, e.MarginBounds.Top + m_HeaderHeight + (m_NextRowToPrint == RangeToPrint.Start.Row ? m_TitleHeight : 0), e.MarginBounds.Width, e.MarginBounds.Height - m_HeaderHeight - (m_NextRowToPrint == RangeToPrint.Start.Row ? m_TitleHeight : 0) - m_FooterHeight); this.DrawHeader(e.Graphics, new RectangleF(e.MarginBounds.Left, e.MarginBounds.Top, e.MarginBounds.Width, m_HeaderHeight), m_PageNo, m_PageCount); if (m_PageNo == 1) { this.DrawTitle(e.Graphics, new RectangleF(e.MarginBounds.Left, e.MarginBounds.Top + m_HeaderHeight, e.MarginBounds.Width, m_TitleHeight), m_PageNo, m_PageCount); } List <int> columnHasTopBorder = new List <int>(); List <int> rowHasLeftBorder = new List <int>(); RangeCollection printedRanges = new RangeCollection(); int pageFirstRow = m_NextRowToPrint; int pageFirstColumn = m_NextColumnToPrint; int pageLastColumn = RangeToPrint.End.Column; // Pre-calculate width of the table in current page float pageColumnWidth = 0; for (int i = m_NextColumnToPrint; i <= RangeToPrint.End.Column; i++) { float colWidth = this.GetColumnWidth(e.Graphics, i); if (i == m_NextColumnToPrint && colWidth > area.Width) { colWidth = area.Width; } if (pageColumnWidth + colWidth <= area.Width) { pageColumnWidth += colWidth; } else { break; } } // Support for fixed row repeat if (RepeatFixedRows && m_Grid.ActualFixedRows > RangeToPrint.Start.Row) { m_NextRowToPrint = RangeToPrint.Start.Row; } float curY = area.Top; while (m_NextRowToPrint <= RangeToPrint.End.Row) { // If repeated rows are printed, resume printing next rows if (RepeatFixedRows && m_NextRowToPrint >= m_Grid.ActualFixedRows && m_NextRowToPrint < pageFirstRow) { m_NextRowToPrint = pageFirstRow; } float rowHeight = this.GetRowHeight(e.Graphics, m_NextRowToPrint); // Check if row fits in current page if (curY + rowHeight > area.Bottom) { break; } float curX = area.Left; while (m_NextColumnToPrint <= pageLastColumn) { float colWidth = this.GetColumnWidth(e.Graphics, m_NextColumnToPrint); // Check if column fits in current page if (curX + colWidth > area.Right) { // If single column does not fit in page, force it if (m_NextColumnToPrint == pageFirstColumn) { colWidth = area.Right - curX; } else { pageLastColumn = m_NextColumnToPrint - 1; break; } } RectangleF cellRectangle; Position pos = new Position(m_NextRowToPrint, m_NextColumnToPrint); Range range = m_Grid.PositionToCellRange(pos); // Check if cell is spanned if (range.ColumnsCount > 1 || range.RowsCount > 1) { Size rangeSize = m_Grid.RangeToSize(range); // Is the first position, draw allways if (range.Start == pos) { cellRectangle = new RectangleF(curX, curY, rangeSize.Width, rangeSize.Height); printedRanges.Add(range); } else { // Draw only if this cell is not already drawn on current page if (!printedRanges.ContainsCell(pos)) { // Calculate offset float sX = curX; for (int i = pos.Column - 1; i >= range.Start.Column; i--) { float cw = this.GetColumnWidth(e.Graphics, i); sX -= cw; } float sY = curY; for (int i = pos.Row - 1; i >= range.Start.Row; i--) { float cw = this.GetRowHeight(e.Graphics, i); sY -= cw; } cellRectangle = new RectangleF(sX, sY, rangeSize.Width, rangeSize.Height); printedRanges.Add(range); } else { cellRectangle = RectangleF.Empty; } } } else { cellRectangle = new RectangleF(curX, curY, colWidth, rowHeight); } if (!cellRectangle.IsEmpty) { SourceGrid.Cells.ICellVirtual cell = this.m_Grid.GetCell(pos); if (cell != null) { CellContext ctx = new CellContext(m_Grid, pos, cell); RectangleF clip = new RectangleF(Math.Max(cellRectangle.Left, area.Left), Math.Max(cellRectangle.Top, area.Top), Math.Min(cellRectangle.Right, area.Left + pageColumnWidth) - Math.Max(cellRectangle.Left, area.Left), Math.Min(cellRectangle.Bottom, area.Bottom) - Math.Max(cellRectangle.Top, area.Top)); Region prevClip = e.Graphics.Clip; try { e.Graphics.Clip = new Region(clip); this.DrawCell(e.Graphics, ctx, cellRectangle); } finally { // Restore clip region e.Graphics.Clip = prevClip; } // Check if left border can be drawn in current page if (!ContainsInRange(rowHasLeftBorder, range.Start.Row, range.End.Row) && cellRectangle.Left >= area.Left) { e.Graphics.DrawLine(m_BorderPen, cellRectangle.Left, clip.Top, cellRectangle.Left, clip.Bottom); AddRange(rowHasLeftBorder, range.Start.Row, range.End.Row); } // Check if top border can be drawn in current page if (!ContainsInRange(columnHasTopBorder, range.Start.Column, range.End.Column) && cellRectangle.Top >= area.Top) { e.Graphics.DrawLine(m_BorderPen, clip.Left, cellRectangle.Top, clip.Right, cellRectangle.Top); AddRange(columnHasTopBorder, range.Start.Column, range.End.Column); } // Check if right border can be drawn in current page if (cellRectangle.Right <= area.Right) { e.Graphics.DrawLine(m_BorderPen, cellRectangle.Right, clip.Top, cellRectangle.Right, clip.Bottom); } // Check if bottom border can be drawn in current page if (cellRectangle.Bottom <= area.Bottom) { e.Graphics.DrawLine(m_BorderPen, clip.Left, cellRectangle.Bottom, clip.Right, cellRectangle.Bottom); } } } // Set next column position curX += colWidth; m_NextColumnToPrint++; } // Set next row Y position curY += rowHeight; m_NextRowToPrint++; m_NextColumnToPrint = pageFirstColumn; } // If we have not reached last column, we will continue on next page if (pageLastColumn != RangeToPrint.End.Column) { m_NextRowToPrint = pageFirstRow; m_NextColumnToPrint = pageLastColumn + 1; } else { m_NextColumnToPrint = RangeToPrint.Start.Column; } this.DrawFooter(e.Graphics, new RectangleF(e.MarginBounds.Left, e.MarginBounds.Bottom - m_FooterHeight, e.MarginBounds.Width, m_FooterHeight), m_PageNo, m_PageCount); // If we have not reached last row we will continue on next page e.HasMorePages = (m_NextRowToPrint <= RangeToPrint.End.Row); // If there are no more pages, release resources if (e.HasMorePages) { m_PageNo++; } }
public virtual System.Drawing.Graphics OnStartPage(PrintDocument document, PrintPageEventArgs e) {}
public PrintPreviewGraphics(PrintDocument document, PrintPageEventArgs e) { _printPageEventArgs = e; _printDocument = document; }
void pdoc_PrintPage(object sender, PrintPageEventArgs e) { // MessageBox.Show(orderid.ToString()); Graphics graphics = e.Graphics; Font font = new Font("Courier New", 10); string customfont = "Courier New"; float fontHeight = font.GetHeight(); int startX = 0; int startY = 0; int Offset = -5; //heder start //logo Image photo = Image.FromFile(@"c:/xampp/htdocs/mpos/images/mpos.png"); //print logo if neccessary //graphics.DrawImage(photo, 10, -60); Offset = Offset + 5; graphics.DrawString("Heritage Cafe & Bistro", new Font("Courier New", 14), new SolidBrush(Color.Red), 0, startY + Offset); Offset = Offset + 20; graphics.DrawString("Z-Report", new Font("Courier New", 12), new SolidBrush(Color.Red), 70, startY + Offset); Offset = Offset + 20; //Report date graphics.DrawString("Report Date ", new Font(customfont, 10), new SolidBrush(Color.Black), startX, startY + Offset); graphics.DrawString(DateTime.Now.ToString("yyyy-MM-dd"), new Font(customfont, 10), new SolidBrush(Color.Black), 150, startY + Offset); Offset = Offset + 15; //Till Open Time graphics.DrawString("Till Open Time ", new Font(customfont, 10), new SolidBrush(Color.Black), startX, startY + Offset); graphics.DrawString(SessionData.tillOpenTime, new Font(customfont, 10), new SolidBrush(Color.Black), 150, startY + Offset); //Till Open Time Offset = Offset + 15; graphics.DrawString("Till Closed Time ", new Font(customfont, 10), new SolidBrush(Color.Black), startX, startY + Offset); graphics.DrawString(DateTime.Now.ToString("HH:mm:ss"), new Font(customfont, 10), new SolidBrush(Color.Black), 150, startY + Offset); //Till closing balance Offset = Offset + 25; graphics.DrawString("Till Open Balance ", new Font(customfont, 10), new SolidBrush(Color.Black), startX, startY + Offset); //Till close time Offset = Offset + 15; graphics.DrawString(String.Format("{0:n}", SessionData.openBalance), new Font(customfont, 10), new SolidBrush(Color.Black), 50, startY + Offset); //Till close time Offset = Offset + 15; graphics.DrawString("Till Closing Balance ", new Font(customfont, 10), new SolidBrush(Color.Black), startX, startY + Offset); //Cashier Offset = Offset + 15; graphics.DrawString(String.Format("{0:n}", SessionData.openBalance + _totalsale), new Font(customfont, 10), new SolidBrush(Color.Black), 50, startY + Offset); //Cashier Offset = Offset + 25; graphics.DrawString("Cashier ", new Font(customfont, 10), new SolidBrush(Color.Black), startX, startY + Offset); graphics.DrawString(SessionData.user, new Font(customfont, 10), new SolidBrush(Color.Black), 150, startY + Offset); String underLine = "-------------------------------"; Offset = Offset + 15; graphics.DrawString(underLine, new Font(customfont, 10), new SolidBrush(Color.Black), startX, startY + Offset); if (_cardwisesale.Rows.Count > 0) { //Title Sales Summery Offset = Offset + 15; graphics.DrawString("Sales Summary", new Font("Courier New", 12), new SolidBrush(Color.Red), 70, startY + Offset); Offset = Offset + 15; graphics.DrawString(underLine, new Font(customfont, 10), new SolidBrush(Color.Black), startX, startY + Offset); Offset = Offset + 10; if (_cardwisesale.Rows != null) { Offset = Offset + 5; graphics.DrawString("Card Type", new Font(customfont, 10), new SolidBrush(Color.Black), startX, startY + Offset); graphics.DrawString("Total", new Font(customfont, 10), new SolidBrush(Color.Black), 150, startY + Offset); Offset = Offset + 15; foreach (DataRow cardwisesalerow in _cardwisesale.Rows) { graphics.DrawString(cardwisesalerow["cardtype"].ToString(), new Font(customfont, 10), new SolidBrush(Color.Black), startX, startY + Offset); graphics.DrawString(String.Format("{0:n}", cardwisesalerow["cardsale"]), new Font(customfont, 10), new SolidBrush(Color.Black), 150, startY + Offset); Offset = Offset + 15; } } } graphics.DrawString(underLine, new Font(customfont, 10), new SolidBrush(Color.Black), startX, startY + Offset); //End cardwise sale //Total card sale if (_totalshiftcardsale.Rows.Count > 0) { Offset = Offset + 30; graphics.DrawString("Total Card Sale", new Font(customfont, 10), new SolidBrush(Color.Black), startX, startY + Offset); Offset = Offset + 15; //shifts if (_totalshiftcardsale != null) { foreach (DataRow cardsaleRows in _totalshiftcardsale.Rows) { graphics.DrawString("Shift " + cardsaleRows["shift_no"].ToString(), new Font(customfont, 10), new SolidBrush(Color.Black), 30, startY + Offset); graphics.DrawString(String.Format("{0:n}", cardsaleRows["cardsale"]), new Font(customfont, 10), new SolidBrush(Color.Black), 150, startY + Offset); Offset = Offset + 15; } } } //Total cash sale if (_totalshiftcashsale.Rows.Count > 0) { Offset = Offset + 15; graphics.DrawString("Total Cash Sale", new Font(customfont, 10), new SolidBrush(Color.Black), startX, startY + Offset); Offset = Offset + 15; //shifts if (_totalshiftcashsale != null) { foreach (DataRow cardsaleRows in _totalshiftcashsale.Rows) { graphics.DrawString("Shift " + cardsaleRows["shift_no"].ToString(), new Font(customfont, 10), new SolidBrush(Color.Black), 30, startY + Offset); graphics.DrawString(String.Format("{0:n}", cardsaleRows["cardsale"]), new Font(customfont, 10), new SolidBrush(Color.Black), 150, startY + Offset); Offset = Offset + 15; } } } //Title void sale if (_voiditems.Rows.Count > 0) { Offset = Offset + 15; graphics.DrawString(underLine, new Font(customfont, 10), new SolidBrush(Color.Black), startX, startY + Offset); Offset = Offset + 15; graphics.DrawString("Void Sale", new Font("Courier New", 12), new SolidBrush(Color.Red), 70, startY + Offset); Offset = Offset + 25; graphics.DrawString(underLine, new Font(customfont, 10), new SolidBrush(Color.Black), startX, startY + Offset); //Void Items if (_voiditems != null) { Offset = Offset + 10; graphics.DrawString("Item", new Font(customfont, 10), new SolidBrush(Color.Black), startX, startY + Offset); graphics.DrawString("Qty", new Font(customfont, 10), new SolidBrush(Color.Black), 110, startY + Offset); graphics.DrawString("Amount", new Font(customfont, 10), new SolidBrush(Color.Black), 170, startY + Offset); Offset = Offset + 15; foreach (DataRow voidItemsRows in _voiditems.Rows) { Offset = Offset + 15; graphics.DrawString(voidItemsRows["name"].ToString(), new Font(customfont, 10), new SolidBrush(Color.Black), startX, startY + Offset); Offset = Offset + 15; graphics.DrawString(voidItemsRows["product_id"].ToString(), new Font(customfont, 10), new SolidBrush(Color.Black), startX, startY + Offset); graphics.DrawString(voidItemsRows["qty"].ToString(), new Font(customfont, 10), new SolidBrush(Color.Black), 110, startY + Offset); graphics.DrawString(String.Format("{0:n}", voidItemsRows["subtotal"]), new Font(customfont, 10), new SolidBrush(Color.Black), 170, startY + Offset); } } } //------------------------------------------------------------------------ //Title Department Sale if (_categorysale.Rows.Count > 0) { Offset = Offset + 15; //underline graphics.DrawString(underLine, new Font(customfont, 10), new SolidBrush(Color.Black), startX, startY + Offset); Offset = Offset + 15; graphics.DrawString("Department Sale", new Font("Courier New", 12), new SolidBrush(Color.Red), 50, startY + Offset); Offset = Offset + 25; graphics.DrawString(underLine, new Font(customfont, 10), new SolidBrush(Color.Black), startX, startY + Offset); //Category wise sale if (_categorysale != null) { Offset = Offset + 10; graphics.DrawString("Category", new Font(customfont, 10), new SolidBrush(Color.Black), startX, startY + Offset); graphics.DrawString("Sale", new Font(customfont, 10), new SolidBrush(Color.Black), 110, startY + Offset); graphics.DrawString("Item Count", new Font(customfont, 10), new SolidBrush(Color.Black), 170, startY + Offset); Offset = Offset + 15; foreach (DataRow catRows in _categorysale.Rows) { Offset = Offset + 15; graphics.DrawString(catRows["name"].ToString(), new Font(customfont, 10), new SolidBrush(Color.Black), startX, startY + Offset); Offset = Offset + 15; graphics.DrawString(catRows["id"].ToString(), new Font(customfont, 10), new SolidBrush(Color.Black), startX, startY + Offset); graphics.DrawString(String.Format("{0:n}", catRows["sale"]), new Font(customfont, 10), new SolidBrush(Color.Black), 110, startY + Offset); graphics.DrawString(catRows["itemcount"].ToString(), new Font(customfont, 10), new SolidBrush(Color.Black), 220, startY + Offset); } } } Offset = Offset + 15; //underline graphics.DrawString(underLine, new Font(customfont, 10), new SolidBrush(Color.Black), startX, startY + Offset); //Total Sale Offset = Offset + 15; graphics.DrawString("Total Sale", new Font(customfont, 10), new SolidBrush(Color.Black), startX, startY + Offset); graphics.DrawString(String.Format("{0:n}", _totalsale), new Font(customfont, 12, FontStyle.Bold), new SolidBrush(Color.Black), 150, startY + Offset); Offset = Offset + 15; //underline graphics.DrawString(underLine, new Font(customfont, 10), new SolidBrush(Color.Black), startX, startY + Offset); Offset = Offset + 2; graphics.DrawString(underLine, new Font(customfont, 10), new SolidBrush(Color.Black), startX, startY + Offset); //Total discount Offset = Offset + 15; graphics.DrawString("Total Discount", new Font(customfont, 10), new SolidBrush(Color.Black), startX, startY + Offset); Offset = Offset + 15; graphics.DrawString(String.Format("{0:n}", _totalDiscount), new Font(customfont, 10), new SolidBrush(Color.Black), 40, startY + Offset); //Total ServiceCharge Offset = Offset + 15; graphics.DrawString("Total Service Charge", new Font(customfont, 10), new SolidBrush(Color.Black), startX, startY + Offset); Offset = Offset + 15; graphics.DrawString(String.Format("{0:n}", _totalServiceCharge), new Font(customfont, 10), new SolidBrush(Color.Black), 40, startY + Offset); Offset = Offset + 15; graphics.DrawString("Total Guest Count", new Font(customfont, 10), new SolidBrush(Color.Black), startX, startY + Offset); graphics.DrawString(_guestcount.ToString(), new Font(customfont, 10), new SolidBrush(Color.Black), 220, startY + Offset); Offset = Offset + 15; //underline graphics.DrawString(underLine, new Font(customfont, 10), new SolidBrush(Color.Black), startX, startY + Offset); Offset = Offset + 10; graphics.DrawString("Powered by mPOS", new Font(customfont, 8), new SolidBrush(Color.Black), 50, startY + Offset); Offset = Offset + 10; graphics.DrawString("+94 117 - 208 375", new Font(customfont, 8), new SolidBrush(Color.Black), 55, startY + Offset); Offset = Offset + 10; }
void PrintImage(object o, PrintPageEventArgs e) { //列印的左上方起始點 Point startPoint = new Point(0, 0); e.Graphics.DrawImage(WWW_Texture2Image(www), startPoint); }
public virtual Graphics OnStartPage (PrintDocument document, PrintPageEventArgs e) { return null; }
private void pd_PrintPage(object sender, PrintPageEventArgs ev) { SizeF tamañoTexto = new SizeF(); Graphics graphics = ev.Graphics; int indexSector; try { if (!buffer.EmptyListFormato()) { if (!buffer.IsModeRead) { buffer.SiguienteFormato(); buffer.SiguientePagina(); buffer.IsModeRead = true; } for (indexSector = 1; indexSector < 5; indexSector++) { FormatoImpresion formato = buffer.GetFormato(); sector.ActualizarPosicion(indexSector); PaintCabecera(formato.Cabecera, graphics, this.sector); FormatoImpresionPagina pagina = buffer.GetPagina(); do { if (buffer.SiguienteLinea()) { buffer.IsModeRead = true; FormatoImpresionPaginaLinea linea = buffer.GetLinea(); switch (linea.TipoLinea) { case FormatoImpresionPaginaLinea.TipoPaginaLinea.TituloArea: tamañoTexto = graphics.MeasureString(linea.Nombre, EstiloFuentePagina.TituloArea); graphics.DrawString(linea.Nombre, EstiloFuentePagina.TituloArea, Brushes.Black, (this.sector.Inicio.X + this.sector.Limite.X) / 2 - tamañoTexto.Width / 2 + this.sector.Configuracion.Margen.Left, this.sector.Cabezal); tamañoTexto.Height += 5; //TITULO DE LABORATORIO break; case FormatoImpresionPaginaLinea.TipoPaginaLinea.TituloExamen: graphics.DrawString(linea.Nombre, EstiloFuentePagina.TituloExamen, Brushes.Black, this.sector.Inicio.X + this.sector.Configuracion.Margen.Left, this.sector.Cabezal); //TITULO DEL EXAMEN tamañoTexto = graphics.MeasureString(linea.Nombre, EstiloFuentePagina.TituloExamen); break; case FormatoImpresionPaginaLinea.TipoPaginaLinea.ItemSimple: graphics.DrawString(linea.Nombre + ": " + linea.Resultado, EstiloFuentePagina.Item, Brushes.Black, this.sector.Inicio.X + this.sector.Configuracion.Margen.Left * 2, this.sector.Cabezal); tamañoTexto = graphics.MeasureString(linea.Nombre, EstiloFuentePagina.Item); break; case FormatoImpresionPaginaLinea.TipoPaginaLinea.ItemTexto: graphics.DrawString(linea.Resultado, EstiloFuentePagina.Item, Brushes.Black, this.sector.Inicio.X + this.sector.Configuracion.Margen.Left * 2, this.sector.Cabezal); tamañoTexto = graphics.MeasureString(linea.Resultado, EstiloFuentePagina.Item); break; case FormatoImpresionPaginaLinea.TipoPaginaLinea.TituloGrupo: graphics.DrawString(linea.Nombre + ": ", EstiloFuentePagina.TituloGrupo, Brushes.Black, this.sector.Inicio.X + this.sector.Configuracion.Margen.Left, this.sector.Cabezal); tamañoTexto = graphics.MeasureString(linea.Nombre, EstiloFuentePagina.TituloGrupo); break; } this.sector.Cabezal += ((int)tamañoTexto.Height + this.sector.Configuracion.Sangria); } else { buffer.IsModeRead = false; if (!buffer.SiguientePagina()) { if (!buffer.SiguienteFormato()) { indexSector = 5; break; } else { buffer.SiguientePagina(); buffer.IsModeRead = true; break; } } else { buffer.IsModeRead = true; break; } } }while (sector.SectorLlenable()); } } ev.HasMorePages = buffer.IsModeRead; } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public override void OnEndPage(PrintDocument prndoc, PrintPageEventArgs ppea) { base.OnEndPage(prndoc, ppea); }
// Event that is emitted at the end of a page. public virtual void OnEndPage (PrintDocument document, PrintPageEventArgs e) { // Nothing to do here. }
private static void printDoc_PrintPage(object sender, PrintPageEventArgs e) { //dgv.Columns[0].Visible = false; //标题字体 Font titleFont = new Font("宋体", 16, FontStyle.Bold); //标题尺寸 SizeF titleSize = e.Graphics.MeasureString(titleName, titleFont, e.MarginBounds.Width); //x坐标 int x = e.MarginBounds.Left; //y坐标 int y = Convert.ToInt32(e.MarginBounds.Top - titleSize.Height); int Ycount = y; //边距以内纸张宽度 int pagerWidth = e.MarginBounds.Width; //画标题 e.Graphics.DrawString(titleName, titleFont, Brushes.Black, x + (pagerWidth - titleSize.Width) / 2, y); y += (int)titleSize.Height; if (titleName2 != null && titleName2 != "") { //画第二标题 e.Graphics.DrawString(titleName2, dgv.Font, Brushes.Black, x, y); Ycount = y; //第二标题尺寸 SizeF titleSize2 = e.Graphics.MeasureString(titleName2, dgv.Font, e.MarginBounds.Width); y += (int)titleSize2.Height;; } //表头高度 int headerHeight = 0; //纵轴上 内容与线的距离 int padding = 5; //所有显示列的宽度 int columnsWidth = 0; //计算所有显示列的宽度 foreach (DataGridViewColumn column in dgv.Columns) { //隐藏列返回 if (!column.Visible) { continue; } //所有显示列的宽度 columnsWidth += column.Width; } //计算表头高度 foreach (DataGridViewColumn column in dgv.Columns) { //列宽 int columnWidth = 0; columnWidth = (int)(Math.Floor((double)column.Width / (double)columnsWidth * (double)pagerWidth)); //表头高度 int temp = (int)e.Graphics.MeasureString(column.HeaderText, column.InheritedStyle.Font, columnWidth).Height + 2 * padding; if (temp > headerHeight) { headerHeight = temp; } } //画表头 foreach (DataGridViewColumn column in dgv.Columns) { //隐藏列返回 if (!column.Visible) { continue; } //列宽 int columnWidth = (int)(Math.Floor((double)column.Width / (double)columnsWidth * (double)pagerWidth)); //内容居中要加的宽度 float cenderWidth = (columnWidth - e.Graphics.MeasureString(column.HeaderText, column.InheritedStyle.Font, columnWidth).Width) / 2; if (cenderWidth < 0) { cenderWidth = 0; } //内容居中要加的高度 float cenderHeight = (headerHeight + padding - e.Graphics.MeasureString(column.HeaderText, column.InheritedStyle.Font, columnWidth).Height) / 2; if (cenderHeight < 0) { cenderHeight = 0; } //画背景 e.Graphics.FillRectangle(new SolidBrush(Color.LightGray), new Rectangle(x, y, columnWidth, headerHeight)); //画边框 e.Graphics.DrawRectangle(Pens.Black, new Rectangle(x, y, columnWidth, headerHeight)); //画内容 e.Graphics.DrawString(column.HeaderText, column.InheritedStyle.Font, new SolidBrush (column.InheritedStyle.ForeColor), new RectangleF(x + cenderWidth, y + cenderHeight, columnWidth, headerHeight)); x += columnWidth; } x = e.MarginBounds.Left; y += headerHeight; //遍历行 while (rowIndex < dgv.Rows.Count) { //if ((bool)dgv.Rows[rowIndex].Cells["CoDelete"].EditedFormattedValue == false) //{ } //else //{ //当前行 DataGridViewRow row = dgv.Rows[rowIndex]; if (row.Visible) { //行高 int rowHeight = 0; //计算行高 foreach (DataGridViewCell cell in row.Cells) { //当前列 DataGridViewColumn column = dgv.Columns[cell.ColumnIndex]; //隐藏列返回 if (!column.Visible || cell.Value == null) { continue; } //列宽 int tmpWidth = (int)(Math.Floor((double)column.Width / (double)columnsWidth * (double)pagerWidth)); //行高 int temp = (int)e.Graphics.MeasureString(cell.Value.ToString(), column.InheritedStyle.Font, tmpWidth).Height + 2 * padding + 20; if (temp > rowHeight) { rowHeight = temp; } } //遍历列 foreach (DataGridViewCell cell in row.Cells) { //当前列 DataGridViewColumn column = dgv.Columns[cell.ColumnIndex]; //if (dgv.CurrentCell.ColumnIndex==0) //{ // continue; //} //隐藏列返回 if (!column.Visible) { continue; } //列宽 int columnWidth = (int)(Math.Floor((double)column.Width / (double)columnsWidth * (double) pagerWidth)); //画边框 e.Graphics.DrawRectangle(Pens.Black, new Rectangle(x, y, columnWidth, rowHeight)); if (cell.Value != null) { //内容居中要加的宽度 float cenderWidth = (columnWidth - e.Graphics.MeasureString(cell.Value.ToString(), cell.InheritedStyle.Font, columnWidth).Width) / 2; if (cenderWidth < 0) { cenderWidth = 0; } //内容居中要加的高度 float cenderHeight = (rowHeight + padding - e.Graphics.MeasureString(cell.Value.ToString(), cell.InheritedStyle.Font, columnWidth).Height) / 2; if (cenderHeight < 0) { cenderHeight = 0; } //画内容 e.Graphics.DrawString(cell.Value.ToString(), column.InheritedStyle.Font, new SolidBrush (cell.InheritedStyle.ForeColor), new RectangleF(x + cenderWidth, y + cenderHeight, columnWidth, rowHeight)); } x += columnWidth; } x = e.MarginBounds.Left; y += rowHeight; if (page == 1) { rowsPerPage++; } //打印下一页 if (y + rowHeight > e.MarginBounds.Bottom) { e.HasMorePages = true; rowIndex++; break; } } rowIndex++; } //} //页脚 string footer = " 第 " + page + " 页,共 " + Math.Ceiling(((double)dgv.Rows.Count / rowsPerPage)).ToString() + " 页"; //画页脚 e.Graphics.DrawString(footer, dgv.Font, Brushes.Black, x + 800, Ycount); //e.Graphics.DrawString(footer, dgv.Font, Brushes.Black, x + (pagerWidth - e.Graphics.MeasureString //(footer, dgv.Font).Width) / 2, e.MarginBounds.Bottom); page++; //dgv.Columns[0].Visible = true; }
static void MyPrintDocument_PrintPage (object sender, PrintPageEventArgs e) { e.Graphics.DrawEllipse (Pens.Black, 50, 50, 100, 100); e.HasMorePages = false; }