//如下的这个方法可以注释掉,没有任何的作用 public void createXmlApp() { // 首先创建文件 FileStream fs = File.Create(Application.StartupPath + "\\xmlAPP.xml"); fs.Close();//关闭文件 //创建 XmlDocument 以便操作 XmlDocument xmlDoc = new XmlDocument(); //xml 唯一的根,我设置的根都是root XmlElement xmlEleRoot = xmlDoc.CreateElement("root"); // 这个配置还有一个是必须的,就是打印机的DPI, 其他的都不是必要的 XmlElement xmlElePrinter = xmlDoc.CreateElement("printer"); //打印机名称,这里直接设置默认打印机 PrintDocument printDoc = new PrintDocument(); xmlElePrinter.SetAttribute("PrinterName", printDoc.PrinterSettings.PrinterName); printDoc.Dispose();//释放资源 //DPI有两个 xmlElePrinter.SetAttribute("DPIX", "600"); xmlElePrinter.SetAttribute("DPIY", "600"); //如下是两个添加操作了 xmlEleRoot.AppendChild(xmlElePrinter); xmlDoc.AppendChild(xmlEleRoot); //保存操作 xmlDoc.Save(Application.StartupPath + "\\xmlAPP.xml"); }
private void PrintPreview() { try { m_PrintDocument = new System.Drawing.Printing.PrintDocument(); m_PrintDocument.BeginPrint += m_PrintDocument_BeginPrint; m_PrintDocument.PrintPage += PrintDocument_PrintPage; m_PrintDocument.PrinterSettings.MaximumPage = CurrentDocument.Count; m_PrintDocument.PrinterSettings.MinimumPage = 1; m_PrintDocument.PrinterSettings.FromPage = 1; m_PrintDocument.PrinterSettings.ToPage = CurrentDocument.Count; m_PrintDocument.DefaultPageSettings.Landscape = CurrentPage.IsLandscape; m_PrintPageIndex = 0; // in case the user prints var dlgPreview = new PrintPreviewDialog { Document = m_PrintDocument, //AutoScrollMargin = new Size(0, 0), //AutoScrollMinSize = new Size(0, 0), ClientSize = new Size(400, 300), //Enabled = true, //UseAntiAlias = true }; PrintMeasures = false; dlgPreview.ShowDialog(); } finally { m_PrintDocument.Dispose(); m_PrintDocument = null; m_PrintDocument.BeginPrint += m_PrintDocument_BeginPrint; m_PrintDocument.PrintPage += PrintDocument_PrintPage; } }
public bool Print(string Text, string FontFamilyName, float FontSize, string printerName) { try { PrinterName = printerName; if (!GetPrinterStatus(printerName)) { throw new ArgumentException("Printer " + printerName + " is currently offline.", "original"); } printingText = Text; printingText = printingText.Replace(Environment.NewLine, "<n>"); printFontDefault = new System.Drawing.Font(FontFamilyName, FontSize); System.Drawing.Printing.PrintDocument pd = new System.Drawing.Printing.PrintDocument(); pd.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(pd_PrintPage); if (PrinterName != "") { pd.PrinterSettings.PrinterName = PrinterName; } pd.Print(); pd.Dispose(); } catch { Debug.LogWarning("Cannot Print!"); return(false); } return(true); }
/// <summary> /// Whether pageheight and pagewidth of the form are same with the specific ones /// </summary> public static bool FormSameSize(string PrinterName, string FormName, decimal Width, decimal Height) { bool bolRet = false; System.Drawing.Printing.PrintDocument pd = new System.Drawing.Printing.PrintDocument(); pd.PrinterSettings.PrinterName = PrinterName; foreach (System.Drawing.Printing.PaperSize ps in pd.PrinterSettings.PaperSizes) { if (ps.PaperName == FormName) { decimal decWidth = FromInchToCM(System.Convert.ToDecimal(ps.Width)); decimal decHeight = FromInchToCM(System.Convert.ToDecimal(ps.Height)); if (System.Math.Round(decWidth, 0) == System.Math.Round(Width, 0) && System.Math.Round(decHeight, 0) == System.Math.Round(Height, 0)) { bolRet = true; } break; } } pd.Dispose(); return(bolRet); }
public void Dispose() { if (doc != null) { doc.Dispose(); } }
private void btnPrintGraph_Click(object sender, EventArgs e) //prints a report { // Create new PrintDocument System.Drawing.Printing.PrintDocument pd = new System.Drawing.Printing.PrintDocument(); pd.DocumentName = "User Analysis Report"; // Add a PrintPageEventHandler for the document pd.PrintPage += new PrintPageEventHandler(pd_PrintPage); printPreviewDialog1.Document = pd; printPreviewDialog1.ShowDialog(); pd.Dispose(); }
public void Close() { pd.Dispose(); try { lineReader.Dispose(); lineReader.Close(); } catch (Exception ex) { Loger.err("打印机释放", ex); } }
private void btnPrint_Click(object sender, EventArgs e) { System.Drawing.Printing.PrintDocument Printer = new System.Drawing.Printing.PrintDocument(); Printer.DefaultPageSettings.Landscape = false; //设置默认纸张页边距,和不设置似乎没有任何区别 Printer.DefaultPageSettings.Margins.Left = 0; Printer.DefaultPageSettings.Margins.Top = 0; Printer.DefaultPageSettings.Margins.Right = 0; Printer.DefaultPageSettings.Margins.Bottom = 0; Printer.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(Printer_PrintPage); Printer.Print(); Printer.Dispose(); Printer = null; }
private void btnPrintGraph_Click(object sender, EventArgs e) { // Create new PrintDocument header = string.Format("{0,-50}{1,-25}{2,-25}{3,-25}", "Email", "Angle", "Event ID", "Event Type") + "\n"; stringToPrint = GetData(Convert.ToDateTime(cmbGarmentStatuses.SelectedValue)); documentContents = stringToPrint; System.Drawing.Printing.PrintDocument pd = new System.Drawing.Printing.PrintDocument(); pd.DocumentName = "User Analysis Report"; // Add a PrintPageEventHandler for the document pd.PrintPage += new PrintPageEventHandler(pd_PrintPage); printPreviewDialog1.Document = pd; printPreviewDialog1.ShowDialog(); pd.Dispose(); }
private void Print(EditableView pnlView) { pnlView.ConcludeOngoing(); try { m_PrintDocument = new System.Drawing.Printing.PrintDocument(); m_PrintDocument.PrinterSettings.MaximumPage = CurrentDocument.Count; m_PrintDocument.PrinterSettings.MinimumPage = 1; m_PrintDocument.PrinterSettings.FromPage = 1; m_PrintDocument.PrinterSettings.ToPage = CurrentDocument.Count; m_PrintDocument.PrinterSettings.PrintRange = PrintRange.CurrentPage; m_PrintDocument.DefaultPageSettings.Landscape = CurrentPage.IsLandscape; m_PrintDocument.BeginPrint += m_PrintDocument_BeginPrint; m_PrintDocument.PrintPage += PrintDocument_PrintPage; if (!Direct) { var dlgPrint = new PrintDialog { AllowSelection = CurrentPage.SelectedCount > 0, Document = m_PrintDocument, AllowCurrentPage = true, AllowSomePages = true, UseEXDialog = true }; if (dlgPrint.ShowDialog() != DialogResult.OK) { return; } } PrintMeasures = false; m_PrintDocument.Print(); } catch (Exception EX) { Utilities.LogSubError(EX); MessageBox.Show(Strings.Item("Print_Error") + " " + EX.Message); } finally { m_PrintDocument.Dispose(); m_PrintDocument = null; } }
/// <summary> /// Whether the specific form is in the selected printer /// </summary> public static bool FormInPrinter(string PrinterName, string PaperName) { bool bolRet = false; System.Drawing.Printing.PrintDocument pd = new System.Drawing.Printing.PrintDocument(); pd.PrinterSettings.PrinterName = PrinterName; foreach (System.Drawing.Printing.PaperSize ps in pd.PrinterSettings.PaperSizes) { if (ps.PaperName == PaperName) { bolRet = true; break; } } pd.Dispose(); return(bolRet); }
public void Debito(string debitoID) { string today = DateTime.Now.Day + "-" + DateTime.Now.Month + "-" + DateTime.Now.Year; SqlDataReader q = dbc.query_single("SELECT c.CL_NOMBRE, r.DEBITOID ,r.PRESTAMOID ,CONVERT(VARCHAR(15), r.HE_FECHA, 105) AS FECHA ,r.CL_CODIGO ,(r.HE_MONTO + r.HE_DESC + r.HE_MORA) As CUOTA ,r.HE_OBSERV FROM debitos r inner join clientes c on (c.CL_CODIGO=r.CL_CODIGO ) where DEBITOID=" + debitoID); if (q.Read()) { rlines[0] = company; rlines[1] = String.Format("{0} \t\t\t\t\t Fecha: {1}", address, q["FECHA"].ToString()); rlines[2] = string.Format("Tel.: {0}, Cel.: {1}", phone, cell); rlines[3] = "____________________________________________ "; rlines[4] = "\t\t\tRecibo De Debito "; rlines[5] = "Recibo No.: " + q["DEBITOID"].ToString() + " Fecha.: " + q["FECHA"].ToString() + " Prestamo.: " + q["PRESTAMOID"].ToString() + " Cliente.: " + q["CL_CODIGO"].ToString(); rlines[6] = "Nombre.......: " + q["CL_NOMBRE"].ToString(); string[] cuotastr = q["CUOTA"].ToString().Split('.'); // split the quota into whole amount and cents long monto = long.Parse(cuotastr[0]); string montocent = cuotastr[1]; rlines[7] = String.Format("Monto Ingreso: {0}Pesos Con {1}/100", Number2Word(monto), montocent).ToUpper(); rlines[8] = "RD$..........: " + q["CUOTA"].ToString(); rlines[9] = "Concepto.....: " + q["HE_OBSERV"].ToString(); rlines[10] = "Valido Si Esta Debidamente Firmado y Cellado\t\t\t____________________"; rlines[11] = "1. Original Cliente / 2. Caja Ingreso / 3. Expediente Cliente"; /// print data PrintDocument pd = new PrintDocument(); // set printing document margins pd.DefaultPageSettings.Margins.Top = 25; pd.DefaultPageSettings.Margins.Left = 25; pd.DefaultPageSettings.Margins.Right = 25; pd.PrintPage += new PrintPageEventHandler(Recibo_PrintPage); // Print the document. pd.Print(); pd.Dispose(); } q.Close(); // return lines; }
/// <summary> /// 设置PrintDocument 的相关属性 /// </summary> /// <param name="PrinterName">打印机名称</param> /// <param name="str">要打印的字符串</param> public void print1(string str) { try { text = str; using (streamToPrint = new StringReader(str)) { printFont = new Font("黑体", 10); titleFont = new Font("黑体", 15); pd = new System.Drawing.Printing.PrintDocument(); //pd.PrinterSettings.PrinterName = PrinterName; //pd.DocumentName = pd.PrinterSettings.MaximumCopies.ToString(); pd.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(this.pd_PrintPage1); pd.PrintController = new System.Drawing.Printing.StandardPrintController(); pd.Print(); pd.Dispose(); }; } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
private void printToolStripMenuItem_Click(object sender, EventArgs e) { System.Drawing.Printing.PrintDocument doc = new System.Drawing.Printing.PrintDocument(); doc.DefaultPageSettings.Landscape = true; doc.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(doc_PrintPage); printDialog1.Document = doc; if (printDialog1.ShowDialog() == DialogResult.OK) { doc.Print(); } doc.Dispose(); }
public static int getPrinterWidth(string sPrinter) { int iSize = 0; PrintDocument pd = new PrintDocument(); pd.PrinterSettings.PrinterName = sPrinter; if (pd.DefaultPageSettings.Landscape) iSize = pd.DefaultPageSettings.PaperSize.Height; else iSize = pd.DefaultPageSettings.PaperSize.Width; pd.Dispose(); return iSize; }
private void Print() { PrintDialog printDialog = new PrintDialog(); PrintDocument printImage = new PrintDocument(); printImage.DocumentName = "Cropper Captured Image"; printImage.PrintPage += OnPrintPage; printDialog.Document = printImage; DialogResult result = printDialog.ShowDialog(); // Send print message try { if (result == DialogResult.OK) printImage.Print(); } catch (InvalidPrinterException) { ShowPrintError(); } finally { printImage.Dispose(); printDialog.Dispose(); } }
/// <summary> /// 这个方法是充满打印 /// </summary> /// <param name="printDetails"></param> private void PrintBarcode2(queuePrintItem printDetails) { //深度拷贝,因为在打印事件中需要调用这个方法 currentQueueItem = ClsXmlSerialization.DeepCopy<queuePrintItem>(printDetails); Shapes myShapes; //首先也是取得纸张的行数和列数 try { myShapes = ClsXmlSerialization.Load<Shapes>(currentQueueItem.ShapesFileName); } catch (System.Exception ex) { return;//如果不能取得,那么就直接返回 } int intNumOfLine = myShapes.BarcodePageSettings.BarcodePaperLayout.NumberOfLine; int intNumOfColumn = myShapes.BarcodePageSettings.BarcodePaperLayout.NumberOfColumn; while ((currentQueueItem.IntCount > 0)) { //如下的才能打印 if (!isprintDocument_PrintPage) { //如下的就是具体构造每一个printDocument了 myPrintDocument = new PrintDocument(); myPrintDocument.DefaultPageSettings.Landscape = myShapes.BarcodePageSettings.BarcodePaperLayout.LandScape;//设置是否横向 int intP = ((queuePrintItemRowAndPages)currentQueueItem.arrlistqueuePrintItemRowAndPages[0]).intPages; //设置多少张纸,这个打印份数只是一个数据的,因为如果第一个没有充满纸张,那么就没必要多份了。 intPrintPage = (int)(intP / (intNumOfLine * intNumOfColumn)); if (intPrintPage == 0)//有时候会出现不足一张的情况 intPrintPage = 1; //根据纸张的连续等问题 //设置打印机 if (strPrinterName != "") { myPrintDocument.PrinterSettings.PrinterName = strPrinterName; } myPrintDocument.PrintController = new StandardPrintController();//这个据说可以不显示那个打印进度对框框 myPrintDocument.DocumentName = "打印条形码";//设置完后可在打印对话框及队列中显示(默认显示document) //打印输出(过程) myPrintDocument.PrintPage += new PrintPageEventHandler(myPrintDocument_PrintPage); myPrintDocument.OriginAtMargins = false;//从位于可打印区域的左上角打印 //必须得设置自定义纸张,要不然会存在顶点问题,比如说有些条形啊打印机的打印宽度为4英寸,而实际纸张宽度不是4英寸,就会存在打印时候顶点是打印机的顶点,而不是实际纸张的顶点。 myPrintDocument.DefaultPageSettings.PaperSize = myShapes.BarcodePageSettings.BarcodePaperLayout.BarcodePaperSize;//设置纸张 //如下是设置边距 /**如下的经测试会产生不可预测的偏移 myPrintDocument.DefaultPageSettings.Margins.Top = (int)(barcodeCanvas.myShapes.BarcodePageSettings.BarcodePaperLayout.Top / 0.254); myPrintDocument.DefaultPageSettings.Margins.Bottom = (int)(barcodeCanvas.myShapes.BarcodePageSettings.BarcodePaperLayout.Bottom / 0.254); myPrintDocument.DefaultPageSettings.Margins.Left = (int)(barcodeCanvas.myShapes.BarcodePageSettings.BarcodePaperLayout.Left / 0.254); myPrintDocument.DefaultPageSettings.Margins.Right = (int)(barcodeCanvas.myShapes.BarcodePageSettings.BarcodePaperLayout.Right / 0.254); * */ //每次打印 myPrintDocument.PrinterSettings.Copies = (short)intPrintPage;//首先就是一次性全部打印完毕,设置份数就是页数. if (myPrintDocument.PrinterSettings.MaximumCopies < intPrintPage)//如果最高能打印的份数比要打印的页数少,就按照最高能打印的份数. myPrintDocument.PrinterSettings.Copies = (short)myPrintDocument.PrinterSettings.MaximumCopies; //如果能多份打印,就需要提前删掉那些,比如说要打印5个,每张纸可以打印2个,那么这里第一次的份数就是2,但是在打印进程中只会减少2个,会造成重复打印 ((queuePrintItemRowAndPages)currentQueueItem.arrlistqueuePrintItemRowAndPages[0]).intPages = ((queuePrintItemRowAndPages)currentQueueItem.arrlistqueuePrintItemRowAndPages[0]).intPages - (myPrintDocument.PrinterSettings.Copies - 1) * (intNumOfLine * intNumOfColumn); try { isprintDocument_PrintPage = true; myPrintDocument.Print(); //这里发出打印消息。 //isprintDocument_PrintPage = true;// 因为上一个打印进程也需要时间,所以这里先设置了。 myPrintDocument.Dispose();//释放 } catch (Exception ex) { MessageBox.Show("没有打印成功,原因:" + ex.Message); isprintDocument_PrintPage = false; return; } } } //保存打印记录,这里用比较省事的方法 ClsDataBase myClsDataBase = new ClsDataBase(); foreach (queuePrintItemRowAndPages item in printDetails.arrlistqueuePrintItemRowAndPages) { myClsDataBase.commandAddPrintedRecord(printDetails.strTableName, item.arrlistRow, item.intPages); OnBarcodePrinted(new printedEventArgs());//发出打印消息 } }
//变量替换,测试成功,如下的准备注释掉,因为不需要了。 /** public static XmlDocument populateVariable(XmlDocument xmlDoc, ArrayList arrlistRow) { //有时候会遇到没arrlistRow为空的情况,那样子就不用变量替换了. if (arrlistRow == null) return xmlDoc; //用xpath搜索的方法来替换。 XmlDocument myxml = xmlDoc;//赋值保存而已 foreach (clsKeyValue keyvalue in arrlistRow) { XmlNodeList nodeList1 = myxml.SelectNodes("//VariableText[@variableName='" + keyvalue.Key + "']"); foreach (XmlNode myXmlNode in nodeList1) { myXmlNode.InnerText = keyvalue.Value; } XmlNodeList nodeList2 = myxml.SelectNodes("//Barcode[@variableName='" + keyvalue.Key + "']"); foreach (XmlNode myXmlNode in nodeList2) { myXmlNode.InnerText = keyvalue.Value; } } return myxml; } * */ private int PrintBarcode(string ShapeFileName, ArrayList arrlist, int intPage) { //首先清零 intPrintPage = 0; try { barcodeCanvas = new VestShapes.UserControlCanvas(); barcodeCanvas.Loader(ShapeFileName);//先加载模板 } catch (Exception ex) { ClsErrorFile.WriteLine("不能加载模板,所以不能打印", ex); MessageBox.Show("不能加载模板,所以不能打印,原因是"+ ex.Message); return 0; //throw; } barcodeCanvas.setArrKeyValue(arrlist);//这个是导入变量用。 int intNumOfLine = barcodeCanvas.myShapes.BarcodePageSettings.BarcodePaperLayout.NumberOfLine; int intNumOfColumn = barcodeCanvas.myShapes.BarcodePageSettings.BarcodePaperLayout.NumberOfColumn; myPrintDocument.DefaultPageSettings.Landscape = barcodeCanvas.myShapes.BarcodePageSettings.BarcodePaperLayout.LandScape;//设置是否横向 //设置多少张纸 intPrintPage = (int)(intPage / (intNumOfLine*intNumOfColumn)); if ((intPage %( intNumOfLine*intNumOfColumn)) != 0)//如果不能整除就多一张纸 intPrintPage++; if (intPrintPage == 0)//有时候会出现不足一张的情况 intPrintPage = 1; int intQty = intPrintPage * intNumOfLine*intNumOfColumn; //如上是计算了要打印多少页,因为有些条形码纸一行有多个,需要在这里打印。 //根据纸张的连续等问题 //设置打印机 if (strPrinterName!="") { myPrintDocument.PrinterSettings.PrinterName = strPrinterName; } myPrintDocument.PrintController = new StandardPrintController();//这个据说可以不显示那个打印进度对框框 myPrintDocument.DocumentName = "打印条形码";//设置完后可在打印对话框及队列中显示(默认显示document) //打印输出(过程) myPrintDocument.PrintPage += new PrintPageEventHandler(printDocument_PrintPage); myPrintDocument.OriginAtMargins = false ;//从位于可打印区域的左上角打印 //必须得设置自定义纸张,要不然会存在顶点问题,比如说有些条形啊打印机的打印宽度为4英寸,而实际纸张宽度不是4英寸,就会存在打印时候顶点是打印机的顶点,而不是实际纸张的顶点。 myPrintDocument.DefaultPageSettings.PaperSize = barcodeCanvas.myShapes.BarcodePageSettings.BarcodePaperLayout.BarcodePaperSize;//设置纸张 //如下是设置边距 /**如下的经测试会产生不可预测的偏移 myPrintDocument.DefaultPageSettings.Margins.Top = (int)(barcodeCanvas.myShapes.BarcodePageSettings.BarcodePaperLayout.Top / 0.254); myPrintDocument.DefaultPageSettings.Margins.Bottom = (int)(barcodeCanvas.myShapes.BarcodePageSettings.BarcodePaperLayout.Bottom / 0.254); myPrintDocument.DefaultPageSettings.Margins.Left = (int)(barcodeCanvas.myShapes.BarcodePageSettings.BarcodePaperLayout.Left / 0.254); myPrintDocument.DefaultPageSettings.Margins.Right = (int)(barcodeCanvas.myShapes.BarcodePageSettings.BarcodePaperLayout.Right / 0.254); * */ //每次打印 myPrintDocument.PrinterSettings.Copies = (short)intPrintPage;//首先就是一次性全部打印完毕,设置份数就是页数. if (myPrintDocument.PrinterSettings.MaximumCopies < intPrintPage)//如果最高能打印的份数比要打印的页数少,就按照最高能打印的份数. myPrintDocument.PrinterSettings.Copies = (short)myPrintDocument.PrinterSettings.MaximumCopies; try { isprintDocument_PrintPage = true; myPrintDocument.Print(); //这里发出打印消息。 myPrintDocument.Dispose();//释放 } catch (Exception ex) { MessageBox.Show("没有打印成功,原因:" + ex.Message); isprintDocument_PrintPage = false; return 0; } //如下是判断是否需要打印间隔 if (isPrintJiange) { PrintDocument printDocPrintJianGe = new PrintDocument(); printDocPrintJianGe.PrintController = new StandardPrintController(); printDocPrintJianGe.DocumentName = "打印间隔"; printDocPrintJianGe.PrinterSettings.Copies = 1;// 间隔只打一份。 printDocPrintJianGe.PrintPage += new PrintPageEventHandler(printDocPrintJianGe_PrintPage); try { printDocPrintJianGe.Print(); printDocPrintJianGe.Dispose();//释放资源 } catch (Exception ex) { MessageBox.Show("没有打印成功,原因:" + ex.Message); return 0; } } return intQty;//返回实际打印的数量 }
/// <summary> /// 打印条码 /// </summary> public void PrintBarCode() { //InitPrintInfo(); printDocument.Print(); printDocument.Dispose(); }
public void Prestamo(string prestamoID) { string today = DateTime.Now.Day + "-" + DateTime.Now.Month + "-" + DateTime.Now.Year; SqlDataReader q = dbc.query_single("SELECT c.CL_NOMBRE, p.PRESTAMOID ,CONVERT(VARCHAR(15), p.CO_FECHA, 105) AS FECHA ,p.CL_CODIGO,p.CO_CAPITAL, p.CO_INTERES,p.CO_CANPAG, p.CO_TIPPAG FROM prestamos p inner join clientes c on (c.CL_CODIGO=p.CL_CODIGO ) where p.PRESTAMOID=" + prestamoID); if (q.Read()) { double cuotafija = GenPrestamoCuotas(q["CO_CAPITAL"].ToString(), q["CO_INTERES"].ToString(), q["CO_CANPAG"].ToString(), q["CO_TIPPAG"].ToString(), q["FECHA"].ToString()); plines[0] = String.Format(company); plines[1] = String.Format("{0} \t\t\t\t\t Fecha: {1}",address, q["FECHA"].ToString()); plines[2] = String.Format("Tel.: {0}, Cel.: {1}",phone,cell); plines[3] = String.Format("____________________________________________ "); plines[4] = String.Format("\t\t\tTABLA DE AMORTIZACION "); plines[5] = String.Format("Numero De Prestamo..: {0}", q["PRESTAMOID"].ToString()); plines[6] = String.Format("Codigo Cliente......: {0}\t{1}",q["CL_CODIGO"].ToString(),q["CL_NOMBRE"].ToString()); plines[7] = String.Format("Fecha...............: {0}", q["FECHA"].ToString()); plines[8] = String.Format("Capital.............: {0:N}", Double.Parse(q["CO_CAPITAL"].ToString())); plines[9] = String.Format("Taza De Interes.....: {0} %", q["CO_INTERES"].ToString()); plines[10] = String.Format("Cantidad De Cuotas.: {0:F0}", Double.Parse(q["CO_CANPAG"].ToString())); plines[11] = String.Format("Forma De Pago......: {0}",getTypo(q["CO_TIPPAG"].ToString())); plines[12] = String.Format("Gasto Legales %....: "); plines[13] = String.Format("Cuota Fija.........: {0:N}", cuotafija); plines[14] = String.Format("FECHA {0,12}{1,15}{2,10}{3,14}{4,10}", "No.Cuota", "Capital", "Interes", "Total Cuota", "Balance"); plines[15] = String.Format("__________ __________ ______________ ___________ ______________ ____________"); /// print data PrintDocument pd = new PrintDocument(); // set printing document margins pd.DefaultPageSettings.Margins.Top = 25; pd.DefaultPageSettings.Margins.Left = 25; pd.DefaultPageSettings.Margins.Right = 25; pd.PrintPage += new PrintPageEventHandler(Prestamo_PrintPage); // Print the document. pd.Print(); pd.Dispose(); } q.Close(); // return lines; }
/// <summary> /// Whether the specific form is in the selected printer /// </summary> public static bool FormInPrinter(string PrinterName, string PaperName) { bool bolRet = false; System.Drawing.Printing.PrintDocument pd = new System.Drawing.Printing.PrintDocument(); pd.PrinterSettings.PrinterName = PrinterName; foreach (System.Drawing.Printing.PaperSize ps in pd.PrinterSettings.PaperSizes) { if (ps.PaperName == PaperName) { bolRet = true; break; } } pd.Dispose(); return bolRet; }
private void button17_Click(object sender, EventArgs e) { PrintDocument PD = new PrintDocument(); PD.PrintPage += new PrintPageEventHandler(printDocument1_PrintPage); PrintPreviewDialog pdlg = new PrintPreviewDialog(); pdlg.Document = PD; pdlg.ShowDialog(); try { PD.Print(); } catch { Console.WriteLine("Yazici çiktisi alinamiyor..."); } finally { PD.Dispose(); } }
public void Print( bool preview ) { if( curr == null ) return; curr.DoOperation( GUI.View.EditOperation.SelectNone ); PrintDocument pd = new PrintDocument(); pd.PrintPage += new PrintPageEventHandler(pd_PrintPage); pd.DefaultPageSettings.Landscape = true; pd.DocumentName = curr.name; pd.DefaultPageSettings.Margins = new Margins( 25,25,25,25 ); pages_printed = 0; PrintDialog d = new PrintDialog(); d.Document = pd; DialogResult res = d.ShowDialog(); if( res != DialogResult.OK ) return; pd.PrinterSettings = d.PrinterSettings; if( preview ) { PrintPreviewDialog ppd = new PrintPreviewDialog(); ppd.Document = pd; ppd.ShowDialog(); } else { pd.Print(); } pd.Dispose(); }
private void DoPrint() { PrintDocument printDocument = null; try { Status = PrintJobStatus.Printing; OnStatusUpdate("Printing Started"); var printerSettings = new PrinterSettings { PrinterName = "Microsoft XPS Document Writer", PrintToFile = true, PrintFileName = string.Format( "{0}\\{1}.xps", FullPrintJobFolder, SOPInstanceUID.UID) }; printDocument = new PrintDocument { PrinterSettings = printerSettings, DocumentName = Thread.CurrentThread.Name, PrintController = new StandardPrintController() }; printDocument.QueryPageSettings += OnQueryPageSettings; printDocument.PrintPage += OnPrintPage; printDocument.Print(); Status = PrintJobStatus.Done; OnStatusUpdate("Printing Done"); } catch { Status = PrintJobStatus.Failure; OnStatusUpdate("Printing failed"); } finally { if (printDocument != null) { //dispose the print document and unregister events handlers to avoid memory leaks printDocument.QueryPageSettings -= OnQueryPageSettings; printDocument.PrintPage -= OnPrintPage; printDocument.Dispose(); } } }
public PrintPreviewDLG(DataTable tblMatrix, DataTable tblVocab) { InitializeComponent(); this.PrintPreviewCtrl.Paint += PrintPreviewCtrl_Paint; this.ZoomFitPageRadio.CheckedChanged += ZoomRadio_CheckedChanged; this.ZoomWidthRadio.CheckedChanged += ZoomRadio_CheckedChanged; this.PrinterTDdl.Items.Clear(); // Do not do the Printer Setup Stuff in Visual Studio Design Mode if (!System.Reflection.Assembly.GetExecutingAssembly().Location.Contains("VisualStudio")) { // Load the Printer Selection List foreach (string sPrinterName in System.Drawing.Printing.PrinterSettings.InstalledPrinters) { this.PrinterTDdl.Items.Add(sPrinterName); } this.PrinterTDdl.SelectedIndex = -1; if (this.PrinterTDdl.SelectedIndex < 0) { // Set the Selected Printer to the Default System Printer System.Drawing.Printing.PrintDocument pd = new System.Drawing.Printing.PrintDocument(); this.PrinterTDdl.SelectedIndex = this.PrinterTDdl.Items.IndexOf(pd.PrinterSettings.PrinterName); pd.Dispose(); } } Layout_ToolBars(); if (System.Reflection.Assembly.GetExecutingAssembly().Location.Contains("VisualStudio")) { // Abort if IDE Design Mode return; } m_MatrixTbl = tblMatrix.Copy(); ReportTools.ReportXPropertiesAdd(ref m_MatrixTbl, true, 0.0f, "CM", 0.0f, 0.0f, 0.0f, 0.0f, ""); m_VocabTbl = tblVocab.Copy(); ReportTools.ReportXPropertiesAdd(ref m_VocabTbl, true, 0.0f, "CM", 0.0f, 0.0f, 0.0f, 0.0f, ""); // Default Page Settings XPageSettings = new PrinterSettings().DefaultPageSettings; XPageSettings.Margins = new Margins(50, 50, 50, 50); XPageSettings.Landscape = false; this.PrintTBtn.Visible = true; this.Width = Convert.ToInt32(Application.OpenForms[0].Width * 0.80); this.Height = Convert.ToInt32(Application.OpenForms[0].Height * 0.80); // Generate the Preview Preview_Puzzle(); }
private void DoPrint() { try { Status = PrintJobStatus.Printing; OnStatusUpdate("Printing Started"); var printerSettings = new PrinterSettings { PrinterName = "Microsoft XPS Document Writer", PrintToFile = true, PrintFileName = string.Format("{0}\\{1}.xps", FullPrintJobFolder, SOPInstanceUID.UID) }; _printDocument = new PrintDocument { PrinterSettings = printerSettings, DocumentName = Thread.CurrentThread.Name, //PrintController = new StandardPrintController() }; _printDocument.PrinterSettings.Collate = true; _printDocument.PrinterSettings.Copies = (short)Session.NumberOfCopies; _printDocument.QueryPageSettings += OnQueryPageSettings; _printDocument.PrintPage += OnPrintPage; PreviewProc(); // I would use some kind of if statement below in a production environment and flow a variable //throught to the sever to triger it "_preview" //if (_preview) // PreviewProc(printDocument); //else // printDocument.Print(); Status = PrintJobStatus.Done; OnStatusUpdate("Printing Done"); } catch { Status = PrintJobStatus.Failure; OnStatusUpdate("Printing failed"); } finally { if (_printDocument != null) { //dispose the print document and unregister events handlers to avoid memory leaks _printDocument.QueryPageSettings -= OnQueryPageSettings; _printDocument.PrintPage -= OnPrintPage; _printDocument.Dispose(); } } }
/// <summary> /// Whether pageheight and pagewidth of the form are same with the specific ones /// </summary> public static bool FormSameSize(string PrinterName, string FormName, decimal Width, decimal Height) { bool bolRet = false; System.Drawing.Printing.PrintDocument pd = new System.Drawing.Printing.PrintDocument(); pd.PrinterSettings.PrinterName = PrinterName; foreach (System.Drawing.Printing.PaperSize ps in pd.PrinterSettings.PaperSizes) { if (ps.PaperName == FormName) { decimal decWidth = FromInchToCM(System.Convert.ToDecimal(ps.Width)); decimal decHeight = FromInchToCM(System.Convert.ToDecimal(ps.Height)); if (System.Math.Round(decWidth, 0) == System.Math.Round(Width, 0) && System.Math.Round(decHeight, 0) == System.Math.Round(Height, 0)) bolRet = true; break; } } pd.Dispose(); return bolRet; }
private void PrinterTDdl_DropDown(object sender, EventArgs e) { // Save_Cfg the currently selected printer object oSave = this.PrinterTDdl.SelectedItem; // Reload the Printer List this.PrinterTDdl.Items.Clear(); this.PrinterTDdl.Text = ""; foreach (string sPrinterName in System.Drawing.Printing.PrinterSettings.InstalledPrinters) { this.PrinterTDdl.Items.Add(sPrinterName); } // Restore previously selected printer this.PrinterTDdl.SelectedItem = oSave; if (this.PrinterTDdl.SelectedIndex < 0) { // Set the Selected Printer to the Default System Printer System.Drawing.Printing.PrintDocument pd = new System.Drawing.Printing.PrintDocument(); this.PrinterTDdl.SelectedIndex = this.PrinterTDdl.Items.IndexOf(pd.PrinterSettings.PrinterName); pd.Dispose(); } }
/// <summary> /// The action of [print] menu click. /// show SelectPluginDialog of PluginManager and select the plugin. /// </summary> /// <param name="sender">object(ToolStripMenuItem)</param> /// <param name="e">EventArgs</param> private void PrintMenuClick(object sender, EventArgs e) { PrintPluginDialog d = new PrintPluginDialog(m_env.PluginManager); DialogResult result = d.ShowDialog(); if (result == DialogResult.OK) { if (d.SelectedItem.Plugin.IsDirect()) { d.SelectedItem.Plugin.Print(d.SelectedItem.Portion); d.Dispose(); return; } PrintDocument pd = new PrintDocument(); PrintDialog pdlg = new PrintDialog(); pdlg.Document = pd; pdlg.AllowSomePages = true; if (pdlg.ShowDialog() == DialogResult.OK) { pd.PrintPage += delegate(object o, PrintPageEventArgs pe) { Bitmap bmp = new Bitmap(d.SelectedItem.Plugin.Print(d.SelectedItem.Portion), pe.PageBounds.Width, pe.PageBounds.Height); pe.Graphics.DrawImage(bmp, new Point(0, 0)); bmp.Dispose(); }; pd.Print(); } pd.Dispose(); } d.Dispose(); }